Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# Angle of 2 points according to right

Posted on 2003-11-02
Medium Priority
333 Views
Hi, I need a function(VB) or a formula for calculating the angle of 2 points according to right, in 2d. I have a standing position(X, Y) and I have a looking position(X, Y) and I want to get the angle from right to the looking position.

- Julian
0
Question by:JulianS
• 2

Accepted Solution

JulianS earned 0 total points
ID: 9693761
I found the solution myself. The solution is to make a triangle with a side on 90*, then you use one of these 2 formulas(Depending on the triangle):

***
Angle = ArcTan(DifferenceX / DifferenceY)

Or

Angle = ArcTan(DifferenceY / DifferenceX)
***

and then you just add: 0, 90, 180 or 270 to the results(also depending on the triangle position)

Here is the VB function of the algorithm:

***

Function GetAngleFromPosition(StandingPositionX As Double, StandingPositionY As Double, LookingPositionX As Double, LookingPositionY As Double) As Double
If StandingPositionX < LookingPositionX Then
If StandingPositionY < LookingPositionY Then
GetAngleFromPosition = (ArcTan(((StandingPositionY - LookingPositionY) / (StandingPositionX - LookingPositionX))))
Else
GetAngleFromPosition = (ArcTan(((StandingPositionX - LookingPositionX) / (StandingPositionY - LookingPositionY)))) + 90
End If
Else
If StandingPositionY < LookingPositionY Then
GetAngleFromPosition = (ArcTan(((StandingPositionY - LookingPositionY) / (StandingPositionX - LookingPositionX)))) + 270
Else
GetAngleFromPosition = (ArcTan(((StandingPositionX - LookingPositionX) / (StandingPositionY - LookingPositionY)))) + 180
End If
End If
End Function

'You need this function to convert radians from Atn to Degrees
Function ArcTan(x As Double) As Double
ArcTan = Atn(x) * (180 / 3.14159265358979)
End Function
***

If you are searching for more formulas like this one go to my web at:

http://www.hostinganime.com/3ddev/

- Julian
0

Author Comment

ID: 9779681
Thanks

- Julian
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of â€¦
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signalâ€¦
###### Suggested Courses
Course of the Month10 days, 4 hours left to enroll