a short post for giving an example of quadrant check (pythagorean theorem):
Function Atan2!(ByVal x!, ByVal y!)
    'On Error Resume Next
    '0 to PI
    If y = 0 Then
        If x = 0 Then
            Atan2 = 0
        ElseIf x > 0 Then
            Atan2 = 0
        Else
            Atan2 = Pi
        End If
    ElseIf x = 0 Then
        If y > 0 Then
            Atan2 = Pi / 2
        Else
            Atan2 = -Pi / 2
        End If
    ElseIf x > 0 Then
        Atan2 = Atn(y / x)
    Else
        Atan2 = (Pi - Atn(Abs(y) / Abs(x))) * Sgn(y)
    End If
End Function

that's vb, but easy enough to translate to mb.
Same one for an angle ranging from 0 to 2 PI

Function Atan2d0_2PI#(ByVal x#, ByVal y#)
    'On Error Resume Next
    '0 to PI
    If y = 0 Then
        If x = 0 Then
            Atan2d0_2PI = 0
        ElseIf x > 0 Then
            Atan2d0_2PI = 0 'PI / 2
        Else
            Atan2d0_2PI = Pi '-PI / 2
        End If
    ElseIf x = 0 Then
        If y > 0 Then
            Atan2d0_2PI = Pi / 2
        Else
            Atan2d0_2PI = 3 * Pi / 2
        End If
    ElseIf x > 0 Then
        If y > 0 Then Atan2d0_2PI = Atn(y / x)
        If y < 0 Then Atan2d0_2PI = 2 * Pi + Atn(y / x)
    Else
        If y > 0 Then Atan2d0_2PI = (Pi - Atn(Abs(y) / Abs(x)))
        If y < 0 Then Atan2d0_2PI = (Pi + Atn(Abs(y) / Abs(x)))

    End If
End Function

Those can be easyly upgraded to get more speed, but they're a good starting
point for comprehension.

Eric.

> -----Message d'origine-----
> De : [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]De la part de Bill Thoen
> Envoy� : lundi 15 octobre 2001 17:17
> � : [EMAIL PROTECTED]
> Objet : Re: MI-L Azimuth
>
>
> Luis Baptista wrote:
> >
> > Hi,
> >
> > there are any query or Function to update a column with an azimuth, in
> > degrees, of a line?
> > The same way I use "ObjectLen" I want to know the azimuth,
> considering North
> > as 0 (zero) degrees, East 90�, South 180� and West 270�.
> >
> > If I don't have a function or something like that to do this,
> how can I find
> > a tool or how can I create it?
>
> There is no "Info" function in MapInfo to return a line's azimuth,
> but there are a couple of ways to calculate it. If your line is
> short enough, the Pythagorean theorem will give you a useable
> result. If your line is long, or you need the accuracy, then use the
> formulae used in great circle navigation (see Ed Williams' Aviation
> formulary page at http://www.best.com/~williams/avform.htm.)
>
> To use the Pythagorean method, you should first set your coordinate
> system to projected units so that distances in y are the same as in
> x for equal units. THen to calculate the angle made between the
> starting and ending points, use:
>
> Ang = Atn (dy/dx) * 57.29577951
>
> Where Ang is the trigonometric angle, dx is the difference between
> your ending point X and starting point X coordinate; dy is similar.
> The number 57.29577951 is simply 180/PI which converts radians to
> degrees. This returns an angle between -90 and 90 degrees.
>
> To find the azimuth, you next have to determine the quadrant and
> apply the proper adjustment. If both dx and dy are positive, you are
> in the first quadrant, so subtract the angle from 90. If dx is
> negative and dy is positive, you are in quadrant 2, so add 360 to
> the angle. Finally, if dy is negative, you are either in quadrant 3
> or 4, but it doesn't matter; just add 180 to the angle to get the
> azimuth.
>
> There's probably a more elegant solution, but that will work. If
> you're working in MapInfo only, then you might have to do column
> updates in several steps, or you can code up these steps in the
> MapBasic window and save the script to use it again.
>
> --
> - Bill Thoen
> ------------------------------------------------------------
> GISnet, 1401 Walnut St., Suite C, Boulder, CO  80302
> tel: 303-786-9961, fax: 303-443-4856
> mailto:[EMAIL PROTECTED], http://www.gisnet.com
> ------------------------------------------------------------
>
>
>
> _______________________________________________________________________
> List hosting provided by Directions Magazine | www.directionsmag.com |
> To unsubscribe, send e-mail to [EMAIL PROTECTED] and
> put "unsubscribe MapInfo-L" in the message body.



_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.

Reply via email to