I would like improve the script below.
The goal of the script is to compute different coordinates corresponding to several angles. This corresponds to rotate one point around x axis and for each step angle retrieve the coordinates.
import numpy as np
# rotating angle
th = np.pi
# starting point (x,y,z coordinates)
ori = [1,1,0]
# how many steps ?
step = 10
# initializing coordinate matrix
# with the starting point
coords = np.array(ori)
# vector containing angles
angles = np.linspace(0,th,step)
# compute new position for each angle in vector angles
for angle in angles:
# adapt Rot matrix with angle
Rot = np.array([
[np.cos(angle),-np.sin(angle),0],
[np.sin(angle),np.cos(angle),0],
[0, 0, 1]
])
# compute new coordinate
new_coord = ori @ Rot
# add new coordinate to coords matrix
coords = np.append(coords, new_coord)
# change shape of coords for esthetical purpose
coords= np.reshape(coords,(-1,3))
print(coords)
I would like to avoid the loop !
Does anyone have an idea for using only matrix calculations to achieve the same result?
Thank you
New contributor
Certes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.