开发者

Finding vector opposite to another?

开发者 https://www.devze.com 2023-01-09 05:51 出处:网络
I need to know how to find a vector opposite to another, but the second vector is not necessarily the same magnitude as the first, but the direction is opposite. Ex:

I need to know how to find a vector opposite to another, but the second vector is not necessarily the same magnitude as the first, but the direction is opposite. Ex:

I made a small diagram :) alt text http://img688.imageshack.us/img688/5394/prettydiagram.png

Basically if I have the coordinates of A(-150,150) and I want B to be opposite, and have a magnitude of only 2, I would want to obtain B(-200,-150). What I am doing is making an application that can draw cubic bezier shapes and I noticed with lots of these, there are bezier handles and mo开发者_C百科difying one handle cause the other one to move too. How could this be done?

Thanks


All you have to do is calculate the unit vector of the original vector by dividing each component by the magnitude of the vector and then apply a rotational transformation about a 180 degree angle.

The rotational transformation matrix looks like this:

Finding vector opposite to another?


(source: equationsheet.com)

Apply the transformation like this:

Finding vector opposite to another?


(source: equationsheet.com)

The primed vector is now the unit vector pointing in the direction you want. You can scale it by any magnitude you wish.

In your special case the angle is 180 degrees. You know that the cosine of 180 is -1 and the sine is zero, so the matrix is simple:

Finding vector opposite to another?


(source: equationsheet.com)

This makes it clear as day: All you have to do is reverse the signs of the two unit vector components and you have your answer.


It is simple, really.

B = -1/2 * A, or B.x = -1/2 * A.x, B.y = -1/2 * A.y, B.z = -1/2 * A.z. This talks about vectors, btw. You would want to shift the result. The formula is dead-simple. What am I missing?

EDIT

Your app knows the red dot location (let's abbreviate it as R vector). Your app also knows the A vector. It needs to find the B vector that is on the same line as AR, on the other side of R as A, and such as A is twice as far than B. Well, in that case:

  • Temporarily calculate vector V = (A - R)
  • Now (It is simple :) ): B = R - 0.5 * V.

It is that simple, I promise. The capital letters represent vectors, which are generally 2-tuples or 3-tuples of real numbers (depending on whether you work in 2D or 3D).

There is not much to this, really. Any questions?

0

精彩评论

暂无评论...
验证码 换一张
取 消