Solved

Calculate angle between two points

Posted on 2009-06-29
9
1,433 Views
Last Modified: 2012-05-07
Math math mat! :D

I got two XY points, what Im trying todo is set the first XY1 to "move towards" XY2, in my application. I assign new XY positions for XY1 every 100ms or so. So to the math:
What I remember from school is that I need to use some sort of variation of the phytagoras theorem?
The new X and Y are C1 and C2 of the right angled triangle, and the hypotenuse is the direction in wich XY2 is relation to XY1.

So I know the length of the hypotenuse and calculate the angle between XY1 and XY2, can I calculate the C1 and C2 from that?

Hope I made sense, math is hellova fun, it's just to hard to manage for some of us.. :P
0
Comment
Question by:Squeese
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 

Author Comment

by:Squeese
ID: 24735103
Ive made a small image illustrating the "problem"


myproblem.gif
0
 
LVL 84

Expert Comment

by:ozo
ID: 24735139
I don't know what you are naming C1 and C2, but
a point that is 100m from X1,Y1 in the direction of X2,Y2 is
X=X1+100m*(X2-X1)/sqrt((X2-X1)^2+(Y2-Y1)^2)
Y=Y1+100m*(Y2-Y1)/sqrt((X2-X1)^2+(Y2-Y1)^2
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24735150
All points while "moving towards" the second point are on the line between the two points.

The equation of a line between two points p1(x1,y1) and p2(x2,y2) is :

    y = y1 + [(y2 - y1) / (x2 - x1)] * (x - x1)

(when x1 is not equal to x2)

To let a point move from p1 to p2, you just let x vary from x1 to x2, and calculate the corresponding y with the above equation.


In the special case where x1 is equal to x2, the equation becomes :

    x = x1

And to let a point move from p1 to p2, you just let y vary from y1 to y2, and calculate the corresponding x with the above equation.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24735171
based on your diagram, it looks like
C1=10*(Y2-Y1)/sqrt((X2-X1)^2+(Y2-Y1)^2)
C2=10*(X2-X1)/sqrt((X2-X1)^2+(Y2-Y1)^2)
0
 

Author Comment

by:Squeese
ID: 24735258
Im naming C1 and C2 out of ignorance to the proper terms I guess, used the shorts for naming the sides of an right angled triangle according to wikipedia: http://en.wikipedia.org/wiki/Cathetus ;P

I tried your solution first ozo and it works absolutely perfect. Much abliged!
0
 
LVL 84

Expert Comment

by:ozo
ID: 24735306
One thing that seemed confusing, was that despite the question title, we nowhere calculated an angle.
0
 

Author Comment

by:Squeese
ID: 24735320
Oh, my lack of mathematical expertise is lacking. :P
Should I rename the Question to a more fitting title, as to help anyone else with similiar problems?

I initially thought it was a prerequisite to solve the math, thw angle that is.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24735324
He probably meant the slope of the line, in which case I did make direct use of it ... (and your solution also indirectly uses it)
0
 

Author Comment

by:Squeese
ID: 24735346
Meaning, if you knew the length of the hypotenuse and the angle, you could thus calculate the length of both cathetus (?).
But what little I actually understand from the given solution, you only need distance between the points to solve it?

C2=10*(X2-X1)/sqrt((X2-X1)^2+(Y2-Y1)^2)
Is that: H = sqrt(c1^2 + c2^2)

Can you use the same formulae to calculate any side of the right angled triange if you know two of them, not only the hypotenuse (as the unknow) ?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where is the math error. 13 74
Quadratic Equation 5 85
Dual bridge protection 18 153
Terminology ..percentile etc 4 75
A Guide to the PMT, FV, IPMT and PPMT Functions In MS Excel we have the PMT, FV, IPMT and PPMT functions, which do a fantastic job for interest rate calculations.  But what if you don't have Excel ? This article is for programmers looking to re…
Complex Numbers are funny things.  Many people have a basic understanding of them, some a more advanced.  The confusion usually arises when that pesky i (or j for Electrical Engineers) appears and understanding the meaning of a square root of a nega…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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