Simple ( I hope) Vector algebra

Started by
4 comments, last by Dakiar 19 years, 10 months ago
I have a velocity vector that goes in a certain direction, for this example let''s say (0.4,0.6,0.2), it starts from the middle point of a sphere that has the radius 0.2 . I want to reach two points on that sphere on each side of the velocity vector. Like if the vector was defining a plane it should rotate 90 degrees along that plane on each side to reach the sphere and when I''d take the coordinates there. Example (I know how to do it for simple Vectors) Velocity vector is (0.0,0.0,5.0) and the center of the sphere is located at (1.0,1.0,1.0) the point of the two coordinates would be (1.2,1.0,1.0) and (0.8,1.0,1.0). It''d be great if someone could help me with the easist(if possible fast code-wise aswell but first and foremost simple) way to do this. Thanx alot, Dakiar
Advertisement
Sadly, there are an infinite number of solutions, because you can rotate around your velocity vector and still have the same plane.

However, the basic answer to the problem is the same as for doing decals, ie for a bullet hitting a wall and leaving a mark. First find a vector which isn't close to parallel to your velocity (any will do, but the closer to perpendicular the better) then take the cross product of it with the velocity. That gives you a vector going sideways to your velocity. Now all you need to do is normalize it and multiply by the radius of the sphere.

A common approach would be to use whatever you think of as the objects local 'up' as the intermediate vector. Alternatively, just pick a not-close-to-parallel axis and use that.

[edited by - squirm on May 28, 2004 12:26:24 PM]
Well, I probably didn''t describe good enough above so I’ll try to clarify a little.

Let''s see I have a velocity vector if I want to make a plane at the beginning of the velocity vector, with each side of it parallel to the velocity vector, I can only see one way of making this plane. Perhaps I’m way of though I’ve been coding math so much that my head hurts badly.
If I get you right, this will do the trick:

Vector a(x, y, z); //your velocity

if(a.x != 0 || a.y != 0)
{
Vector b(a.y, -a.x, 0);
Vector c = a.cross(b);
}
else if(a.z != 0)
{
Vector b(-a.z, 0, a.x);
Vector c = a.cross(b);
}
else //a is (0, 0, 0)...
fail();
quote:Original post by Dakiar
Well, I probably didn't describe good enough above so I’ll try to clarify a little.

Let's see I have a velocity vector if I want to make a plane at the beginning of the velocity vector, with each side of it parallel to the velocity vector, I can only see one way of making this plane. Perhaps I’m way of though I’ve been coding math so much that my head hurts badly.

Planes don't have sides, so further clarification is needed. The only way in which a single vector can define a plane is by indicating the perpendicular to the plane.

Also, in your first example, why is the solution (1.2,1,1) and (.8,1,1), and not (1,1.2,1) and (1,.8,1)?

[edited by - Alvaro on May 28, 2004 2:20:16 PM]
Bleh my explaning really sucks maybe if I am to explain what to use it for it'll be easier.

The sphere in this case is a (o) ball and I want to fire several rays / in the direction of the velocity vector, and each one are to start at the edge of the ball in the direction of that other line \ I have drawn. . equals nothing. Imagine that the rays are fired from the middle between the XX's.

I know this is 2d but... thinking more about it maybe I can't do it as easily as I thought in 3d, any suggestions are welcome.

........................................................
.oooo.\/....................................................
ooXXoo\/...................................................
.oooo....\/.....................................................
Well my beautifull ASCII art was destroyed when the message was formated. I hope this one explains something


[edited by - Dakiar on May 28, 2004 3:30:29 PM]

[edited by - Dakiar on May 28, 2004 3:30:48 PM]

[edited by - Dakiar on May 28, 2004 3:31:12 PM]

[edited by - Dakiar on May 28, 2004 3:31:26 PM]

[edited by - Dakiar on May 28, 2004 3:32:16 PM]

[edited by - Dakiar on May 28, 2004 3:33:15 PM]

This topic is closed to new replies.

Advertisement