Skip to content

Instantly share code, notes, and snippets.

@mithi
Created February 17, 2020 05:36
Show Gist options
  • Select an option

  • Save mithi/71c92fe3ed9b477f3bd059aa2d220095 to your computer and use it in GitHub Desktop.

Select an option

Save mithi/71c92fe3ed9b477f3bd059aa2d220095 to your computer and use it in GitHub Desktop.
https://math.stackexchange.com/questions/40164/how-do-you-rotate-a-vector-by-a-unit-quaternion
https://www.3dgep.com/understanding-quaternions/
https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/897677#897677
https://stackoverflow.com/questions/1171849/finding-quaternion-representing-the-rotation-from-one-vector-to-another
https://stackoverflow.com/questions/14812005/rotate-plane-so-its-normal-is-the-same-direction-as-another-planes-normal
https://answers.unity.com/questions/1221564/rotate-plane-by-normal-how-to-calculate-new-positi.html
https://stackoverflow.com/questions/1023948/rotate-normal-vector-onto-axis-plane
https://stackoverflow.com/questions/57694061/how-can-i-use-the-rotation-angle-and-axis-to-rotate-a-3d-plane
Rotate plane by normal, how to calculate new position?
I hava a plane, which I know the normal(normal0), and 2 points(pointA, pointB).
Now I have another normal:normal1.
I need to rotate plane from normal0 to normal1 around pointA, How can I know the new position pointB after rotation?
Vector3 changeNormal(Vector3 normal0, Vector3 normal2, Vector3 pointA, Vector3 pointB) {
Quaternion rotation = Quaternion.FromToRotation(normal0, normal2); //Get rotation between both normals
Vector3 rotationDir = pointB - pointA; // Get point direction relative to pivot
rotationDir = rotation * rotationDir; // Rotate it
pointB = rotationDir + pointA; // Calculate rotated point
return pointB;
}
Calculate Rotation Matrix to align Vector A to Vector B in 3d?
import numpy as np
import math
def rotation_matrix(A,B):
# a and b are in the form of numpy array
ax = A[0]
ay = A[1]
az = A[2]
bx = B[0]
by = B[1]
bz = B[2]
au = A/(np.sqrt(ax*ax + ay*ay + az*az))
bu = B/(np.sqrt(bx*bx + by*by + bz*bz))
R=np.array([[bu[0]*au[0], bu[0]*au[1], bu[0]*au[2]], [bu[1]*au[0], bu[1]*au[1], bu[1]*au[2]], [bu[2]*au[0], bu[2]*au[1], bu[2]*au[2]] ])
return(R)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment