15,959,474 members
1.00/5 (1 vote)
See more:
Hello,

what i need to do is to rotate a point around a vector.

i have the vector x1 y1 z1 and x2 y2 z2 . i also have the point x y z and the angle of rotation.

can anybody help me?

thank you

What I have tried:

i'm trying to use the code ( http://blog.kjeldby.dk/wp-content/uploads/rotate.txt ) but it works fine only when degrees is set to 0, otherwise it gives number out of any logic.
Posted
Updated 22-Apr-17 0:24am
Richard MacCutchan 22-Apr-17 4:35am
No one here can guess what that code is doing wrong.
[no name] 22-Apr-17 6:05am
Most probably a Thing (mix up) with rad (0...2pi) vs. degree (0...360)?

Solution 2

Most probably a Thing (mix up) with rad (0...2pi) vs. degree (0...360)?

Especally Remarks: The angle, d, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.

What does it mean:
C#
```// Degree will "fail", respectively not deliver the expected result
VectorMath :: Rotate(v, axis, 40.0)```
vs.
C#
```// Rad should work
VectorMath :: Rotate(v, axis, 40.0 * Math.PI/180.0)```

Hope it helps.

v4

Solution 1

This isn't terribly efficient but should work. You need to compose a transformation matrix - a 3x3 or - if using homogeneous coordinates - a 4x4.

a. matrix to translate to (-x1, -y1, -z1) so that x1,y1,z1 are now all zero.
b. matrix to rotate by theta XZ so that (x2,y2,z2) is now in the YZ plane (x2 becomes zero).

You will need to remember some geometry to calculate theta XZ.

c. matrix to rotate by theta YZ so that (x2,y2,z2) is now the Z axis (x2 and y2 are zero).

You will need to remember some geometry to calculate theta YZ.

d. matrix to rotate about the Z axis (in the XY plane) by your angle of rotation.
e. apply the inverse of (c) above.
f. apply the inverse of (b) above.
g. apply the inverse of (a) above.

You can concatenate the above matrices into a single matrix and apply that to your point (x,y,z). If using a 4x4 matrix, don't forget to normalize the result.