How do I perform coordinate transformation such that there are three 3D vectors A, B, and C, where AB is applied to the x-axis of the 2D space and AC is applied to the y-axis of the 2D space?
As an amateur, I would like to do the following, but I can't set up a specific program...
Thank you for your cooperation.
python numpy
Based on Takoika's response, we were able to convert vectors using gram Schmidt's regular orthogonalization method
Include the program, test case, and diagram.
>>import numpy as np
>>def transform(a,b,c,p):
... v1 = b-a
... v2 = c-a
... u1 = v1
... u1 = u1/np.linalg.norm(u1)
... u2 = v2 - (np.dot(u1,v2)/np.dot(u1,u1))*u1
... u2 = u2/np.linalg.norm(u2)
... u3 = np.cross(u1, u2)
... u3 = u3/np.linalg.norm(u3)
... rot = np.array ([u1, u2, u3])
... return np.dot(rot, p-a)
...
>>>A=np.array((2,0,0))
>>>B=np.array(2,2,0))
>>>C=np.array(2,2,2))
>>>p1=np.array(0,1,0))
>> transform (A, B, C, p1) [:2]
array([1.,0.])
>>>p2=np.array(0,1,1))
>> transform (A, B, C, p2) [:2]
array([1.,1.])
>>>p3=np.array(0,0,1))
>> transform (A, B, C, p3) [:2]
array([0,1.])
>>>p4 = np.array ((3,0,1))
>> transform (A, B, C, p4) [:2]
array([0,1.])
for a given coordinate p
1. Move A in parallel so that A is the origin (p-A)
2. The x-axis of AB, the y-axis of AC, the z-axis of AB and AC (think in the right hand system), multiplied by the rotation matrix R for such conversion R*(p-A)
Let me explain how to make a rotation matrix. First, let the vector AB be normalized as the vector b. Similarly, let the vector AC be normalized as c. Let the vector d be the outer product of b and c. We want the rotation matrix R to be the x, y, and z axes, respectively.
Rb=(1,0,0)
Rc=(0,1,0)
Rd=(0,0,1)
R^-1 = (b, c, d), R^-1 is a matrix of 3x3 in which vertical vectors b, c, d are arranged.
Hence R=(b,c,d)^-1=(b,c,cross(b,c))^-1
import numpy
A = numpy.array ([0.1, 0.1, 0.1])
B = numpy.array ([2,1,5])
C = numpy.array ([1, 10, -1])
b=(B-A)
b=b/numpy.linalg.norm(b)
c=(C-A)
c=c/numpy.linalg.norm(c)
d = numpy.cross(b,c)
R=numpy.linalg.inv(numpy.array([b,c,d]))
default(p):
return numpy.dot(R,p-A)
© 2024 OneMinuteCode. All rights reserved.