DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. jerek Guest

## Angle Determination?

I have a grid that I've set up.. with a starting point (x,y) and a secondary
point (x2, y2), and I want to determine a compass direction (just the basic
8 directions).

How do you determine an angle in VB given the reference point and target
point?

2. Dean Earley Guest

## Re: Angle Determination?

This gives you the angle in degree around 0

Function Angle(X As Single, Y As Single) As Integer

If X = 0 Then X = 1
If (X < 0) Then
Angle = 270 + (Atn(Gradient) * (180 / 3.14159265358979))
Else
Angle = 90 + (Atn(Gradient) * (180 / 3.14159265358979))
End If

Do While Angle > 359
Angle = Angle - 360
Loop
End Function

to use X1 and X2, try:
Angle (X2 - X1, Y2 - Y1)

--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer

iCode Systems
"jerek" <vztwins@usa.net> wrote in message news:3bd6fc71\$1@news.devx.com...
>
> I have a grid that I've set up.. with a starting point (x,y) and a secondary
> point (x2, y2), and I want to determine a compass direction (just the basic
> 8 directions).
>
> How do you determine an angle in VB given the reference point and target
> point?

3. Anthony Jones Guest

## Re: Angle Determination?

Dean,

>

Do While Angle > 359
Angle = Angle - 360
Loop
>

Something wrong with Angle = Angle Mod 360? ;-)

--
Anthony Jones
Nuesoft Ltd

4. Dean Earley Guest

## Re: Angle Determination?

> Dean,
>
> >

> Do While Angle > 359
> Angle = Angle - 360
> Loop
> >

>
> Something wrong with Angle = Angle Mod 360? ;-)
>

Doh!

I haven't used this for about a year, I dug it out of my archive )
I was using it in a Palm graffitti emulater.

--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer

iCode Systems

5. Bob O`Bob Guest

## Re: Angle Determination?

Anthony Jones wrote:
>
> Dean,
>
> >

> Do While Angle > 359
> Angle = Angle - 360
> Loop
> >

>
> Something wrong with Angle = Angle Mod 360? ;-)

....and just look what happens to 359.001!

Bob
--
Seems to me we went through the whole copy-protection thing decades ago,
and smart folks realized it can only hurt the customer.

6. Dean Earley Guest

## Re: Angle Determination?

"Bob O`Bob" <bob@cluestick.org> wrote in message news:3BDCB047.3D7A@cluestick.org...
> Anthony Jones wrote:
> >
> > Dean,
> >
> > >

> > Do While Angle > 359
> > Angle = Angle - 360
> > Loop
> > >

> >
> > Something wrong with Angle = Angle Mod 360? ;-)

>
>
> ...and just look what happens to 359.001!
>
>

Function Angle(X As Single, Y As Single) As INTEGER

but if you want to be perfect ) ...

Do While Angle => 360
Angle = Angle - 360
Loop

--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer

iCode Systems

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise