Shooting a ray from a plane( and determine it's new direction)

Hi I have defined a ray segment in 2d( and extended this to 3d by using polar coordinates) to get the direction of the ray shooting of from the 2d plane say for instance (.707, .707 , 0 ) where is the ‘y’ value means shooting away from the plane. But now i want to map these direction onto a plane in 3D, while mainting direction, but relative from the 3d plane. Any Pointers?

Pual

Two options come to mind (if I understand your problem):

  1. Do all the drawing in 2Dand use glRotate on the modelview matrix to place your plane and vector to the correct oreintationin 3D (and glTranslate to move the plane if it is supposed to be in a different place). Then you don’t need polar coordinates, but depending on what else you’re doing in the scene, that may not be as useful… but if you can make this work, the performance is probably best.

  2. Calculate how the plane’s orientation was changed (without more information about how your geometry is stored, I’m not sure what the best way to do this would be for you), and rotate the vector. This could use glRotate also, or if you want to do the calculation on the processor side, you could use a Quaternion technique. The below code snippet will do this (it uses the vecmath package from Java3D).


//r is the Vector3f to rotate about, diff is the Vector3f to rotate, angle is the angle to rotate in degrees
Quat4f v = new Quat4f();
v.set(diff.x,diff.y,diff.z,0);
Quat4f z = new Quat4f();
z.set(new AxisAngle4f(r,(float)Math.toRadians(angle)));
//perform v = z*v*z^-1:
v.mulInverse(z);
v.mul(z,v);
//vVec is the rotated vector 
Vector3f vVec =  new Vector3f(v.x,v.y,v.z);

after some thinking it’s much simpler i guess, i have a point somewehere on a plane( location is known) and the normal of the plane. What i need now is to rotate around the normal of the of the plane ( 0…360 degrees) and ‘away’ from the plane (0…90 degrees) so basically when i draw lines with the rotated vector i get a cone.
Any pointers:)

Paul

Well, either of the two techniques I mentioned should work for that - if you draw a plane in the x-y axis, you can rotate about the z axis as rotation about th normal. I’m not sure exactly what you mean by rotating “away” from the axis, but if you mean rotation by the axis perpendicular to the normal and the vector from the center of the plane to the point, you could either use the quaternionic method I mentioned above, or use glRotate to line the point up along the x or y axis(probably a rotation about the z axis), rotate around that axis, and then invert the z rotation… I’m not absolutely sure that’ll do quite what you want, but the quaternion method certainly will. Is that helpful?

(It’s hard to talk about geometry in prose… wish I could draw a diagram…)