Thanks Bill I guess what I am really looking for is an angle of a line drawn
from 0,0 to any point, given only the point coordinates.  for instance in
your example below if you use x = 20, y = -50  and * 180/pi you get -68
degrees. When what I need is 291.8 degrees. So below is my Angle to point
function which calculates the angle to the point from 0,0 counterclockwise
from the x plane. Basically I needed to replicate AutoCAD's angle to point
function. So I phrased my earlier question quite poorly. Here is what I did
with a brief example of how it's used.

Include "mapbasic.def"

Declare Sub Main
Declare Function AngleOfPt(ByVal dblY As Float, ByVal dblX As Float) As
Float 

Sub Main
Dim flY As Float
Dim flX As Float
Dim flAngle As Float
flX = 20
flY = -50
flAngle = AngleOfPt(flY,flX) 

If flAngle <> 1004 Then
        Note flAngle
Else
        Note "Both X and Y cannot be equal to Zero."
End If

End Sub




Function AngleOfPt(ByVal dblY As Float, ByVal dblX As Float) As Float
 Dim PI As Float
  PI = 3.14159265358979
 
 If dblX = 0 AND dblY < 0 Then
        AngleOfPt = 270
 ElseIf dblX = 0 AND dblY > 0 Then
        AngleOfPt = 90
 ElseIf dblX > 0 AND dblY >= 0 Then
        AngleOfPt = Atn(dblY / dblX) * 180 / PI
 ElseIf dblX < 0 AND dblY > 0 Then
        AngleOfPt = 180 - (Atn(dblY / Abs(dblX)) * 180 / PI)
 ElseIf dblX < 0 AND dblY <= 0 Then
        AngleOfPt = 180 + (Atn(dblY / dblX) * 180 / PI )
 ElseIf dblX > 0 AND dblY < 0 Then
        AngleOfPt = 360 - (Atn(Abs(dblY) / dblX) * 180 / PI)
 ElseIf dblX = 0 AND dblY = 0 Then
        AngleOfPt = 1004
 End If
 
 
 
 
End Function

-----Original Message-----
From: B. Thoen [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 23, 2003 6:22 AM
To: Canfield, Andrew
Cc: [EMAIL PROTECTED]
Subject: Re: MI-L Command line compile instructions


On Thu, 23 Jan 2003, Canfield, Andrew wrote:

> Second question does anyone have a Mapbasic Atan2 function that they would
> like to share? 

>From Ed Williams' "Aviation Formulary" page at 
http://williams.best.vwh.net/avform.htm#Math, Ata2(x,y) can be defined as:

   atan2(y,x)=atan(y/x)       x>0
   atan2(y,x)=atan(y/x)+pi    x<0, y>=0
   atan2(y,x)=pi/2            x=0, y>0
   atan2(y,x)=atan(y/x)-pi    x<0, y<0
   atan2(y,x)=-pi/2           x=0, y<0
   atan2(0,0) is undefined and should give an error.

- Bill Thoen



---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 5107

Reply via email to