0

I've got the following problem: In 3D there's a vector from fixed the center of a plane to the origin. This plane has arbitrary coordinates around this center thus its normal vector is not necessarily the mentioned vector. Therefore I have to rotate the plane around this fixed center such that the mentioned vector is the plane's normal vector.

My first idea was to compute the angle between the vector and the normal vector, but the problem then is how to rotate the plane.

Any ideas?

Dänis
  • 29
  • 3
  • I think your first idea is correct, you just have to split it into 2 operations: calculate the x angle, rotate around z, then calculate the y angle, rotate around x. – user2328447 Dec 21 '17 at 12:31
  • What have you tried so far? Nobody will give you plain code or algorithm unless you show us your own effort in solving this problem – Fureeish Dec 21 '17 at 12:31
  • I wasn't looking for someone who will provide me code, but for someone who might give me mathemaical help, like which operations are needed. – Dänis Dec 21 '17 at 12:40
  • How is the plane defined in code? – amc176 Dec 21 '17 at 12:45
  • ok thank you user2328447 i think this could work. I think that was the point that was missing in my idea. – Dänis Dec 21 '17 at 12:51
  • 1
    the plane is an OpenGl Quad so it is defined by its four edges, but if I just transform this matrix with a rotationmatrix for the x and y angle it should work – Dänis Dec 21 '17 at 12:53

1 Answers1

0

A plane is a mathematical entity which satisfies the following equation:

enter image description here

Where n is the normal, and a is any point on the plane (in this case the center point as above). It makes no sense to "rotate" this equation - if you want the plane to face a certain direction, just make the normal equal to that direction (i.e. the "mentioned" vector).

You later mentioned in the comments that the "plane" is an OpenGL quad, in which case you can use Quaternions to compute the rotation.

This Stackoverflow post tells you how to compute the rotation quaternion from your current normal vector to the "mentioned" vector. This site tells you how to convert a quaternion into a rotation matrix (whose dimensions are 3x3).

Let's suppose the center point is called q, and that the rotation matrix you obtain has the following form:

enter image description here

This can only rotate geometry about the origin. A rotation about a general point requires a 4x4 matrix (what OpenGL uses), which can be constructed as follows:

enter image description here

meowgoesthedog
  • 14,670
  • 4
  • 27
  • 40