Solved

Angle of 2 points according to right

Posted on 2003-11-02
3
323 Views
Last Modified: 2013-12-26
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.

Thanks in advance.

 - Julian
0
Comment
Question by:JulianS
  • 2
3 Comments
 

Accepted Solution

by:
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

by:JulianS
ID: 9779681
Thanks

- Julian
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now