Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: √ ∞ ≠ ≤ ≥ ≈ ⇒ ∈ Δ θ ∴ ∑ ∫ π -

Login

Username

Password

Not registered yet?

  • Index
  •  » Help Me !
  •  » calculate position c based on position a and b

Post a reply

Go back

Write your message and submit
:) :| :( :D :o ;) :/ :P :lol: :mad: :rolleyes: :cool: | :dizzy :eek :kiss :roflol :rolleyes :shame :down :up :touched :sleep :wave :swear :tongue :what :faint :dunno
Options

Go back

Topic review (newest first)

Ricky
2005-12-05 06:42:33

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.

safra
2005-12-05 03:00:49

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)

Ricky
2005-12-05 01:06:08

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.

safra
2005-12-05 00:34:02

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!

MathsIsFun
2005-12-04 22:49:54

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.

safra
2005-12-04 22:00:12

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.

Board footer

Powered by FluxBB