Skip to main content
gamedev.net
🔒 Locked

Vector/Plane Adjustment

Started by Zerosix Sep 18, 2006 at 10:24 AM 5 replies 900+ views
Original Post
Zerosix
Zerosix
If I have a point(P) in space and an associated direction vector (V). What is the best method to translate P such that it can move an arbitrary distance along the plane to which V is perpendicular? An example of this would be spawning an entity near another object but has the same directional vector.
haegarr
haegarr
Could you please concretize your question? Do you mean that the given point and direction vectors are anywhere in space, but you need them to be projected onto the plane, so that the point becomes a location on the plane, and the direction becomes a vector parallel to the plane?
TheAdmiral
TheAdmiral
If your problem requires production of a perpendicular vector, you should instantly be thinking 'cross-product'. The result of the cross-product of any two non-zero, linearly independent vectors is guaranteed to be perpendicular to them both. Assuming V isn't zero, you can use this fact, along with vector normalisation, to achieve what you are after:

Create a vector, any vector, that isn't zero or parallel to V:
W = (1, 1, 1)if (abs(W . V) == 1) W = (1, -1, 1)
Now take the cross-product:
U = V x W
Now we know that U lies somewhere in the plane orthogonal to V. So normalise it:
U = U / |U|
Then use the result to create a new position vector:
Q = P + s.U
Where s is the distance to set Q away from P. If you need something more specific, I'm sure you can adapt this method to your liking.

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Zerosix
Zerosix
I will try to re-explain. I have a point(P) in space which could be anywhere. I also have a directional vector(V) to discribe where the point is looking. A plane exists to which V is perpendicular. How do I create/move an object an offset along the plane a direction and distance from P.

For Example,

P = [5,5,5]
V = [.5,.245,.182]

I want to adjust P in space along the plane to which V is perpendicular by say 4 units at 130 degrees.

TheAdmiral...are you saying to create a vector which is perpendicular to my vector and simply move along it? Am I making this more complicated than it really is?

[Edited by - Zerosix on September 18, 2006 5:52:29 PM]
TheAdmiral
TheAdmiral
Quote:
Original post by Zerosix
...are you saying to create a vector which is perpendicular to my vector and simply move along it?

That's exactly what I am saying, and unless I have completely misunderstood the problem, that's the simplest way to achieve what you seek.

Any vector perpendicular to V must be coplanar with the plane you speak of, so that plane will be invariant under translation along such a vector.

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Zerosix
Zerosix
So then, I would just rotate around my vector to attain the actual position I want to use?

Thanks! :)

[Edited by - Zerosix on September 19, 2006 9:55:15 AM]
TheAdmiral
TheAdmiral
Well, that works but it seems like three sides of a square.

If you know exactly which direction in the plane you want to perturb, then there's no need for any of the calculation I described [wink].
But if you only know the rough direction in which the new point should be created, you can use that as a displacement vector and project it into the plane perpendicular to V. From here, you can normalise and translate as before:

Supposing V is the 'facing' vector we had from the start and W is a vector roughly in the direction we want to perturb. Then, provided W isn't parallel to V, we'll construct a vector A, which lies in the aforementioned plane, pointing mostly towards W. Here's a quick derivation:
A = W + sV    // A is W translated by some unknown amount (s) of V, so that it is...A . V = 0     // perpendicular to V(W + sV) . V = 0W.V + sV.V = 0W.V + s = 0s = -W.V

Hence:
A = W - (W.V)V


All that's left is to normalise A and use it to translate from P.

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.