You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**safra****Member**- Registered: 2005-12-03
- Posts: 41

Hi there,

My maths are a bit rusty.

I have 2 objects A and B in a 2 dimensional world. I need to calculate the x and y position of object C. C is positioned on the line between A and B and I know that for example the distance between B and C is 5. How can I get the position of B. I know I have to do something with the angles and cosinus or sinus. But I really complete forgot about this.

Hope anyone can help me with this, thanks.

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,608

It is actually easy if you know more about the position of A and B. You probably won't need sine or cosine.

Do you know the (x,y) of points A nd B? If so you can use slope etc to help you out.

Feel free to tell us more about your problem, and one of us can give you the formulas.

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**safra****Member**- Registered: 2005-12-03
- Posts: 41

Thanks a lot for responding so quick and great forum (it took me about 5 secs of googling to find it)!

Actually this is a directx 3d issue. I have 2 objects (a and b) on the scene and I would like to place the cam (object C, which will render the visible part of the 3d world) behind object b in the direction of object A. The cam is always positioned on a predefined distance of object B. So you know the positions of object A and B. In directx you work with 3 coordinates but this issue doesn't include the y (vertical) plane only horizontal and depth.

For example the coordinates of A are 50 (x) and 70 (z) and the coordinates of B are 10 (x) and 80 (z), the distance between B and C should be 5. What are the exact x and z coordinates of object C?

Actually, it would also be nice if you would have the formula for all 3 planes.

Thanks!

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

You have a points A and B, (ax, ay) and (bx, by). The vector between these two points is <ax - bx, ay - by>, going from B to A. Now what you need is the unit vector. To get this, we divide that vector by it's length. So let L = √( (ax - bx)² + (ay - by)² ), which is the length. <(ax - bx) / L, (ay - by) / L> is the unit vector. Then multiply this by the distance you want the camera, D: <D*(ax - bx) / L, D*(ay - by) / L>.

So Cx = bx + D*(ax - bx) / L and Cy = by + D*(ay - by) / L. This is because that vector will be the distance you have to travel from b to get to c, so to find the position of c, you just add the vector to that of b.

For all three planes, all you do is add in a z value:

A: (ax, ay, az)

B: (bx, by, bz)

Vector: <ax - bx, ay - by, az - bz>

L: √( (ax - bx)² + (ay - by)² + (az - bz)² )

Unit vector: <(ax - bx) / L, (ay - by) / L>

So you get Cx = bx + D*(ax - bx) / L, Cy = by + D*(ay - by) / L, and Cz = bz + D*(az - bz) / L.

*Last edited by Ricky (2005-12-04 02:39:49)*

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**safra****Member**- Registered: 2005-12-03
- Posts: 41

Thanks Ricky, I think I got it to work.

I did a test, am I right that C will always be a point between A and B in your formula? I need C to be a point 'behind' B with B being on the vector between A and C. I came up with this, which seems to be ok:

Cx = bx + -1*(D*(ax - bx) / L)

Cy = by + -1*(D*(ay - by) / L)

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Ah, sorry, I misread your post. But yes, that is precisely right. By multiplying the vector by -1, you are reversing it's direction, so in front becomes behind.

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

Pages: **1**