Re:Math problems RadToDeg & Sin
Quote
Fredrik T wrote in message <6qd4a2$g...@forums.borland.com>...
>Hi everyone!
>I'm currently expering problems in a project of mine. I would like to
>calculate the sinand cos for a angel. Delphi calculates the value in
>radians. so far everythings works accodring to plan.
>But I want to convert it to DEG. When I use the function RadToDeg the
answer
>returned doesn't match the value I get when calculating the Degree sin on a
>ordinary calculator.
>for example sin 45 degrees should be approx 0,707xxx. when calculated with
>Delphi and then converted using RadToDeg I get an answer saying 30.xx
>Can someone give me a clue on how to get around this problem?
>Thank you on beforehand
>Fredrik Tholander
>Sweden
I had the same problem a while a go . i wrote these functions to solve it.
Steve Beaulieu
S...@Mediaone.net
{***************************************************************************
* Radians - converts degrees to radians *
* Degrees - converts radians to degrees *
* CosD - cosine in degrees *
* SinD - sine in degrees *
* TanD - tangent in degrees *
* CotD - CoTangent in degrees *
* ArcTanD - ArcTangent in degrees *
* Power - power a^n *
* DMS_TO_RAE - Converts two sets of lat lons *
* to range azimuth and elevation *
****************************************************************************
Unit LatMath;
Interface
Const
Ln10 = 2.30258509299405E+000; { Ln( 10 ) = 2.3025651 }
OneOverLn10 = 0.43429448190325E+000; { 1 / Ln( 10 ) = 0.4342945 }
PiOver180 = 1.74532925199433E-002; { Pi / 180 = 0.0174533 }
PiUnder180 = 5.72957795130823E+001; { 180 / Pi = 57.2957795 }
{**************************************************************************}
Function Power(Base : Real; Exponent : Integer) : Real;
Function SinD(Angle : Real) : Real;
Function ArcTanD(Angle : Real) : Real;
Function CotD(Angle : Real) : Real;
Function TanD(Angle : Real) : Real;
Function CosD(Angle : Real) : Real;
Function Degrees(Angle : Real) : Real;
Function Radians(Angle : Real) : Real;
Procedure DMS_To_RAE( VAR LatRef,LonRef,HightRef,
LatCase,LonCase,HightCase,
ToAZ,FromAz,Rng,El : Real );
Implementation
{***************************************************************************
Function Radians(Angle : Real) : Real;
Begin
Radians := Angle * PiOver180 { Angle * Pi / 180 }
End;
{***************************************************************************
Function Degrees(Angle : Real) : Real;
Begin
Degrees := Angle * PiUnder180 { Angle * 180 / Pi }
End;
{***************************************************************************
Function CosD(Angle : Real) : Real;
Begin
CosD := Cos( Radians( Angle ) )
End;
{***************************************************************************
Function TanD(Angle : Real) : Real;
Begin
TanD := Sin( Radians( Angle ) ) / Cos( Radians( Angle ) )
End;
{***************************************************************************
Function CotD(Angle : Real) : Real;
Begin
CotD := Cos( Radians( Angle ) ) / Sin( Radians( Angle ) )
End;
{***************************************************************************
Function ArcTanD(Angle : Real) : Real;
Begin
ArcTanD := Degrees(ArcTan( Angle ))
End;
{***************************************************************************
Function SinD(Angle : Real) : Real;
Begin
SinD := Sin( Radians( Angle ) )
End;
{***************************************************************************
Function Power(Base : Real; Exponent : Integer) : Real;
Var
BPower : Real;
t : Integer;
Begin
If (Exponent = 0) Then
Power := 1
Else
Begin
BPower := 1.0;
For t := 1 To Exponent Do
BPower := BPower * Base;
Power := BPower
End
End;
{***************************************************************************
{**************************************************************************}
{***************************************************************************
* LatRef = INPUT Latitude of Refferance site In Degrees *
* LonRef = INPUT Longitude of Refferance site In Degrees *
* HightRef = INPUT MSL of Refferance site In Feet *
* LatCase = INPUT Latitude of Case site In Degrees *
* LonCase = INPUT Longitude of Case site In Degrees *
* HightCase = INPUT AGL of Case site In Feet *
* RNG = OUTPUT Distance in feet from reff site to case site *
* ToAz = OUTPUT Azimuth in Degrees from reff site to case site *
* FromAz = OUTPUT Azimuth in degrees from case sith to reff site *
* El = OUTPUT Elevation Angel from reff site *
* to case site (5/6 earth curve) *
****************************************************************************
Procedure DMS_To_RAE( VAR LatRef,LonRef,HightRef,
LatCase,LonCase,HightCase,
ToAZ,FromAz,Rng,El : Real );
Const
Goof = 0.0000000001;
VAR
LonDiff, TMP1, TMP2,
LatRefmLatcaseD2,
LatRefPLatcaseD2 : REAL;
Begin
If LatRef = LatCase Then LatRef := LatRef + Goof;
If LonRef = LonCase Then LonRef := LonRef + Goof;
If LonCase >LonRef Then
LonDiff := LonCase - LonRef
Else
LonDiff := LonRef - LonCase;
LatRefmLatcaseD2 := (LatRef-LatCase)/2;
LatRefPLatcaseD2 := (LatRef+LatCase)/2;
Tmp1 := ArcTanD( CotD(LonDiff/2)*SinD(LatRefMLatcaseD2)
/CosD(LatRefPLatcaseD2) );
Tmp2 := ArcTanD( CotD(LonDiff/2)*CosD(LatRefMLatcaseD2)
/SinD(LatRefPLatcaseD2) );
If LonRef>LonCase Then
Begin
ToAz := (tmp2+tmp1);
FromAz := 360 - (Tmp2 - Tmp1);
End
Else
Begin
ToAz := 360 - (Tmp2 + Tmp1);
FromAz := (Tmp2 - Tmp1);
End;
Rng :=((ArcTanD( TanD(LatRefMLatcaseD2)*
SinD(tmp2)/SinD(tmp1)))*2)*60.00*6076.1;
EL := ArcTanD(((HightCase-HightRef)-
((Power(RNG/6076.1,2)*5)/6))/(RNG));
End;
(***************************************************************************
**)
End.