1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > matlab y轴旋转面 Mayavi:绕y轴旋转

matlab y轴旋转面 Mayavi:绕y轴旋转

时间:2021-11-20 21:19:02

相关推荐

matlab y轴旋转面 Mayavi:绕y轴旋转

你需要一些数学知识。好的,这里是如何做到这一点的代码,这不是最好的代码,但我想让它自解释。我用罗德里格斯公式在三维旋转来实现这一点,azéu new和el_new是您的新视角。改变θ的值以获得不同的视角,我在下面的代码中使用了45度:import numpy as np

import math

def rotation_matrix(axis, theta):

"""

Return the rotation matrix associated with counterclockwise rotation about

the given axis by theta radians.

"""

axis = np.asarray(axis)

theta = np.asarray(theta)

axis = axis/math.sqrt(np.dot(axis, axis))

a = math.cos(theta/2.0)

b, c, d = -axis*math.sin(theta/2.0)

aa, bb, cc, dd = a*a, b*b, c*c, d*d

bc, ad, ac, ab, bd, cd = b*c, a*d, a*c, a*b, b*d, c*d

return np.array([[aa+bb-cc-dd, 2*(bc+ad), 2*(bd-ac)],

[2*(bc-ad), aa+cc-bb-dd, 2*(cd+ab)],

[2*(bd+ac), 2*(cd-ab), aa+dd-bb-cc]])

az = 90

el = -75

x = np.cos(np.deg2rad(el))*np.cos(np.deg2rad(az))

y = np.cos(np.deg2rad(el))*np.sin(np.deg2rad(az))

z = np.sin(np.deg2rad(el))

# So your viewing vector in x,y coordinates on unit sphere

v = [x,y,z]

# Since you want to rotate about the y axis from this viewing angle, we just increase the

# elevation angle by 90 degrees to obtain our axis of rotation

az2 = az

el2 = el+90

x = np.cos(np.deg2rad(el2))*np.cos(np.deg2rad(az2))

y = np.cos(np.deg2rad(el2))*np.sin(np.deg2rad(az2))

z = np.sin(np.deg2rad(el2))

axis = [x,y,z]

# Now to rotate about the y axis from this viewing angle we use the rodrigues formula

# We compute our new viewing vector, lets say we rotate by 45 degrees

theta = 45

newv = np.dot(rotation_matrix(axis,np.deg2rad(theta)), v)

#Get azimuth and elevation for new viewing vector

az_new = np.rad2deg(np.arctan(newv[1]/newv[0]))

el_new = np.rad2deg(np.arcsin(newv[2]))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。