emergency9177
New member
- Joined
- Dec 16, 2021
- Messages
- 19
Use 8 vectors to describe corners of a cube, which is centered in the axis system, with sides aligned with coordinate system.
Next, scale cube in x, y and z direction by a0, b0 and c0.
Write a function, which will generate a matrix for scaling.
In the next step, generate rotation matrices and rotate the scaled cube by a1, b1 and c1 angles around x, y and z axis.
Prepare a program using numpy that will calculate and print out the vectors of the scaled and rotated cube.
Check if the order of scaling and rotation change the result.
_______________________________________________________________________________________________________________________________________________________________________
Untill now I've tried to write an algorithm using Numpy. I am not sure about the code, because I cannot find the right code to connect the vertices (cornes) of the cube in x, y and z direction by a0, b0 and c0, ; generating rotation matrices to rotate the scaled cube by a1, b1 and c1 angles around x, y and z axis.
When I run the program it works independently if I put the values of the vertices or not.
Thanks for help.
This is what I've solved:
Next, scale cube in x, y and z direction by a0, b0 and c0.
Write a function, which will generate a matrix for scaling.
In the next step, generate rotation matrices and rotate the scaled cube by a1, b1 and c1 angles around x, y and z axis.
Prepare a program using numpy that will calculate and print out the vectors of the scaled and rotated cube.
Check if the order of scaling and rotation change the result.
_______________________________________________________________________________________________________________________________________________________________________
Untill now I've tried to write an algorithm using Numpy. I am not sure about the code, because I cannot find the right code to connect the vertices (cornes) of the cube in x, y and z direction by a0, b0 and c0, ; generating rotation matrices to rotate the scaled cube by a1, b1 and c1 angles around x, y and z axis.
When I run the program it works independently if I put the values of the vertices or not.
Thanks for help.
This is what I've solved:
Python:
import numpy as np
from math import sin,cos
vertices = np.array(
[
[-1, -1, -1],
[+1, -1, -1],
[+1, +1, -1],
[-1, +1, -1],
[-1, -1, +1],
[+1, -1, +1],
[+1, +1, +1],
[-1, +1, +1],
]
)
def test_double_rotation():
data['vectors'][0] = numpy.array([[-1, -1, -1],
[+1, -1, -1],
[+1, +1, -1],
[-1, +1, -1],
[-1, -1, +1],
[+1, -1, +1],
[+1, +1, +1],
[-1, +1, +1],])
combined_rotation_matrix = numpy.dot(rotation_matrix, rotation_matrix)
def get_rx(angle):
cs = cos(angle*np.pi/180.)
sn = sin(angle*np.pi/180.)
return np.array([[1.0,0.0,0.0],[0.0,cs,-sn],[0.0,sn,cs]])
def get_ry(angle):
cs = cos(angle*np.pi/180.)
sn = sin(angle*np.pi/180.)
return np.array([[cs,0.0,sn],[0.0,1.0,0.0],[-sn,0.0,cs]])
def get_rz(angle):
cs = cos(angle*np.pi/180.)
sn = sin(angle*np.pi/180.)
return np.array([[cs,-sn,0.0],[sn,cs,0.0],[0.0,0.0,1.0]])
def dot(m,a):
c1 = np.sum(m[0,:] * a)
c2 = np.sum(m[1,:] * a)
c3 = np.sum(m[2,:] * a)
return np.array([c1,c2,c3])
print(get_rx(30.0))
#print(get_ry(30.0))
#print(get_rz(30.0))
mx = get_rx(30.0)
my = get_ry(60.0)
mz = get_rz(45.0)
a = np.array([0.,0.,0.])
print("a:",a)
print("Rx a;" ,np.dot(mx,a))
print("RyRx a;" ,np.dot(my,np.dot(mx,a)))
print("RzRyRx a;" ,np.dot(mz,np.dot(my,np.dot(mx,a))))
r = np.dot(mz,np.dot(my,mx))
print("R = (RzRyRx) a;" ,np.dot(r,a))
print("\n----------------------")
import numpy.linalg as ln
print("\nR :\n" ,r)
rinv = ln.inv(r)
print("\nR-1:\n" ,rinv)
print("\nR :\n" ,a)
ra = np.dot(r,a)
print("\nRa :\n" ,ra)
rb = np.dot(rinv,ra)
print("\nRinvRa :\n" ,rb)