What's new

Math help needed, a little trig and geometry I think (1 Viewer)

Keith Mickunas

Senior HTF Member
Joined
Dec 15, 1998
Messages
2,041
I'm trying to solve a problem for work. Here's what I'm dealing with in generic terms:

I've got two points, P1 = x1,y1 and P2 = x2,y2. Obviously I know the distance between those, lets call that d1. I'm trying to set find a third point called P3 = x3,y3. I'm given d2, the distance between x1,y1 and x3,y3, and d3, the distance between x2,y2, and x3, y3.

Technically there's two possible answers, but I'll know which one to pick. This is really just a matter of finding the third point on a triangle, given two points and the length of each side. Obviously if d1 > d2 + d3 I don't have a solution, but I can handle that.
 

Andrew Testa

Second Unit
Joined
Mar 22, 2002
Messages
263
So you have a triangle where you know the coordinates of two points and the length of each side.You want to find the coordinates of the third point. This point will be at the two mirror locations where the end of d2 and d3 are the same.

So think of a circle centered on each known point with its known radius.

d2^2 = (x1-x3)^2 + (y1-y3)^2

d3^2 = (x2-x3)^2 + (y2-y3)^2

You now have two equations and two unknowns (x3 and y3). The rest is algebra.

Andy

EDIT:

Brian, we don't know that it's a right triangle, so a direct calculation of the angles isn't possible. If we don't know at least one angle we can't apply either of the law of sines or cosines. but we do have enough information for an algebraic solution.
 

Keith Mickunas

Senior HTF Member
Joined
Dec 15, 1998
Messages
2,041
Andy, I've been trying the same thing you came up with. But I'm thinking two equations with two unkowns is easy to solve only when the two equations are linear. It's been a long time since I worked with that though, so maybe I'm forgetting something.

There's another part of this problem that may help. I'm actually placing a third round object against two other round objects. Their diameters may be different though, and the first two may or may not touch.

When the first two touch, the answer isn't too bad. I believe that if you draw a line from the P3 to the point at which the first two objects connect, you'll be left with two right triangles. Thus the solution is straightforward from that point. I know this is the case when the first two objects are of the same diameter, whether they are touching or not.
 

Brandon_T

Screenwriter
Joined
Oct 3, 2000
Messages
1,903
d2-d3= d1-2x2^2-2y2^2+2x1(x2-x3)+2y1(y2-y3)
I believe this is the equation you would get by subtracting the equation for D3 from that of D2 (and substituting in the equation for D1). If you then use this equation (before substitutingin D1) to get X3 in terms of y3 or vice versa(below) you should get a an equation for only one of them. By substituting one of those into this equation it is simply plug and play with your given numbers.

Y3= (D2-D3-X1^2+X2^2-Y1^2+Y2^2+2X1X3)/2Y2
X3= (D2-D3-X1^2+X2^2-Y1^2+Y2^2-2Y2Y3)/2X2

I think this works I haven't done this in quite a while.
 

Lee L

Supporting Actor
Joined
Oct 26, 2000
Messages
868
Are you trying to solve this theoretically or is this solving a real word problem and if so, what is it?
 

Keith Mickunas

Senior HTF Member
Joined
Dec 15, 1998
Messages
2,041
I'm trying to solve it for real. It's a space optimization problem. There's a lot more to it, as in I have many more than three, but I've reduced the core problem to this bit.
 

Keith Mickunas

Senior HTF Member
Joined
Dec 15, 1998
Messages
2,041
Things just got a whole lot simpler for me. I've found the law of cosines.

I've got a,b and c (dist1 and so on from my earlier descriptions). Once I've found the angles I can work from there to find the coordinates for the missing point.

I've got one problem though. I've worked the equation to this:
C = acos((a^2 + b^2 - c^2) / 2ab)
I'm doing this in C and acos in C is arccosine. The problem is the C function only accepts a value between -1 and 1 and will return the angle in radians. So I either need to reduce my answer to ensure a value between -1 and 1, or figure out a way to use atan which can take any double. I've found thelaw of tangents, but it's worse.

So can anybody tell me how to change my formula above to use atan or how to make sure the value lies in between -1 and 1?
 

Keith Mickunas

Senior HTF Member
Joined
Dec 15, 1998
Messages
2,041
Never mind, I found the answer here .

My boss wanted me to place the third object where I knew it wouldn't intersect, then gradually reduce x and y and see when it intersects the other two. Yeah, that's a good way to do it. Sure it took me a while to find this answer, but it's going to be sweet once I implement it.
 

Users who are viewing this thread

Sign up for our newsletter

and receive essential news, curated deals, and much more







You will only receive emails from us. We will never sell or distribute your email address to third party companies at any time.

Forum statistics

Threads
357,034
Messages
5,129,195
Members
144,286
Latest member
acinstallation172
Recent bookmarks
0
Top