- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我正在从事一个项目,我需要从服务器检索粒子数据(可能会获取多达数千个对象)(以便同步客户端),并且我正在努力找出轨道如何计算多个粒子的倾 Angular 。
到目前为止,我已经有了轨道总半径、宽度(粒子的起点和终点)
var asteroidsOrbit = Common.random( 90, 100),
rotation = Math.PI / 2, // Not sure where to use this yet
radians = Common.random(0, 360) * Math.PI / 180;
我还通过设置粒子需要的位置来渲染轨道:
position_x: Math.sin(radians) * asteroidsOrbit,
position_y: Common.random(-10, 10),
position_z: Math.cos(radians) * asteroidsOrbit
我注意到默认情况下轨道垂直于 X 平面,表现得理所当然。但是我应该如何对其应用旋转
,因为它可能在 x 平面上旋转 20 度?
最佳答案
我用 Python 编写了一些代码,将旋转应用于 3D 空间中的粒子速度,可能会有所帮助:
def make_rotation_matrix(theta=0.,phi=0.,cos_theta=False,cos_phi=False):
"""
Returns a rotation matrix for given angles.
Makes the rotation matrix for a given theta angle around the y axis (polar
angle) followed by another rotation around the z axis by a given phi angle
(azimuthal angle).
Parameters
----------
theta : float
Polar angle, between 0 and pi (or its cosine between -1 and 1).
phi : float
Azimuthal angle, between 0 and 2pi.
cos_theta : boolean
Wether to consider theta as an angle (False) or its cosine (True).
cos_phi : boolean
Wether to consider phi as an angle (False) or its cosine (True).
Returns
----------
out : np.array
Rotation matrix (shape == (3,3)).
Examples
--------
>>> make_rotation_matrix(0,10)
array([[-0.83907153, 0.54402111, -0. ],
[-0.54402111, -0.83907153, -0. ],
[-0. , 0. , 1. ]])
>>> make_rotation_matrix(10,0)
array([[-0.83907153, -0. , -0.54402111],
[-0. , 1. , -0. ],
[ 0.54402111, 0. , -0.83907153]])
>>> make_rotation_matrix(0.1,0,True)
array([[ 0.1 , -0. , 0.99498744],
[ 0. , 1. , 0. ],
[-0.99498744, 0. , 0.1 ]])
"""
if cos_theta:
cos_theta = theta
sin_theta = np.sqrt(1. - cos_theta**2)
else:
cos_theta = np.cos(theta)
sin_theta = np.sin(theta)
if cos_phi:
cos_phi = phi
sin_phi = np.sqrt(1. - cos_phi**2)
else:
cos_phi = np.cos(phi)
sin_phi = np.sin(phi)
return np.array(
[[cos_theta*cos_phi , -sin_phi , sin_theta*cos_phi],
[cos_theta*sin_phi , cos_phi , sin_theta*sin_phi],
[ -sin_theta , 0 , cos_theta ]])
def skew_symmetric_cross_product(vector):
"""
Returns the skew symmetric cross product of given vector.
Parameters
----------
vector : iterable
Iterable object, must have at least 3 elements, corresponding to
the vectors x, y and z components.
Returns
----------
out : np.array
Skew symmetric cross product of the given vector (shape == (3,3)).
Examples
--------
>>> skew_symmetric_cross_product([1,0,0])
array([[ 0., 0., 0.],
[ 0., 0., -1.],
[ 0., 1., 0.]])
>>> skew_symmetric_cross_product([0,1,0])
array([[ 0., 0., 1.],
[ 0., 0., 0.],
[-1., 0., 0.]])
>>> skew_symmetric_cross_product([0,0,1])
array([[ 0., -1., 0.],
[ 1., 0., 0.],
[ 0., 0., 0.]])
"""
return np.array([[ 0. , -vector[2] , vector[1] ],
[ vector[2] , 0. , -vector[0] ],
[ -vector[1] , vector[0] , 0. ]])
def rotation_a2b(a,b):
"""
Returns the rotation matrix that transforms vector a in b.
From
http://math.stackexchange.com/questions/180418/
Parameters
----------
a : iterable
Iterable object, must have at least 3 elements, corresponding to
the vectors x, y and z components.
b : iterable
Similar to a.
Returns
----------
out : np.array
Rotation matrix that transforms a in b (shape == (3,3)).
Examples
--------
>>> rotation_a2b([1,0,0],[1,0,0])
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> rotation_a2b([1,0,0],[0,1,0])
array([[ 0., -1., 0.],
[ 1., 0., 0.],
[ 0., 0., 1.]])
>>> rotation_a2b([1,0,0],[0,0,1])
array([[ 0., 0., -1.],
[ 0., 1., 0.],
[ 1., 0., 0.]])
"""
if np.all(a==b):
return np.identity(3)
v = np.cross(a,b)
v_sscp = skew_symmetric_cross_product(v)
s = np.sqrt(np.dot(v,v))
c = np.dot(a,b)
return np.identity(3) + v_sscp +\
(((1-c)/(s**2))*np.dot(v_sscp,v_sscp))
摘录 self 的报告[编辑]:
由于旋转是围绕粒子速度 (vp
) 进行的,因此由 make_rotation_marix
生成的矩阵 R
不能直接应用于 vp
- 我们必须首先更改基础以使速度与 (0, 0, 1) 向量共线,应用旋转,然后将基础更改回原始值。由于第一个基础变化的结果已知为 (0, 0, sp),sp 是粒子的速度(速度大小),因此跳过第一个基础变化并且 R
应用于 (0, 0, sp)。
为了将基础改回,我们使用矩阵将 (0, 0, 1) 改回初始粒子速度,由函数 Rotation_a2b
提供。矩阵 Ra2b
将向量 a
转换为 b
,因此调用时使用 a
= (0, 0, 1 ) 和 b 等于归一化粒子的初始速度。事实上,我们对速度进行归一化意味着基数的变化保留了向量的大小 - 或者可以使用 a = (0, 0, sp)。
关于javascript - 3 维空间中的轨道倾 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42318070/
我想使用 Orbited 进行聊天。我还找到了 Orbited2。有什么不同? Orbited 死了没有?我想用solid solution,不用担心会被关闭或不支持。我还没有找到任何关于 Orbit
我最近开始学习SFML,我有一个问题,如何使第二个物体在轨道上运动,请帮助。 #include using namespace sf; int main() { RenderWindow wi
我正在尝试使用 Tweepy 获取所有带有关键字的推文,但它没有返回某些关键字的任何内容。例如,如果使用 Obama 作为关键字,我会收到很多推文,如果我使用 Arduino,我不会收到任何返回信息,
在我看来,我有一个复选框和一个标签。我正在使用 SLIM,所以代码是 = check_box_tag 'All Products' = label_tag 'All Products' 生成的等效 H
正如倾斜所暗示的那样,我试图弄清楚如何嵌入 soundcloud 文件,以及如何轻松更改嵌入的声音.. 我有一个网站,目前,让用户写一个故事,然后附加一个图像或视频。对于视频,我使用 vimeo 和
我创建了一个在应用程序的实际背景上绘制的 slider 轨道,并且还绘制了 UISlider 拇指图像。我知道如何设置 slider 的缩略图。但如何隐藏 UISlider 轨道呢? 最佳答案 如果你
从 HTTP 链接下载的 Windows Media DRM 轨道是否可以合法渐进播放? 我已经设法在没有 DRM 的情况下做到了这一点,但这里有人告诉我,使用 DRM 是不可能的。这是真的? 如果是
我有一个简单的 vtt 轨道文件编辑器,其中构建的 vtt 文件内容保存在 var vtt 中. 目前我通过保存vtt的内容来添加轨道。到文件,然后将文件读取为 我想省略保存到文件的步骤,直接将变量
我有一个简单的应用程序,用户可以在其中的文本字段中输入内容以获得各种结果。我想要一个功能,如果用户输入某些内容然后关闭浏览器选项卡,下次他们来时,我可以向他们展示他们之前/最近的搜索。即使他们关闭整个
我试图在不同的线程中同时运行 4 个 MP3 轨道。我正在使用 JLayer1.0 MP3 library播放 MP3。鉴于我无法控制线程何时启动,我使用 CountDownLatch 至少让它们同时
我可以在我的 Android 应用程序中播放来自 SoundCloud 的轨道吗?我正在尝试这段代码,但它不起作用: String res = "https://api.soundcloud.com/
我正在使用 Apple Music API 的 recent played endpoint返回最近播放的媒体 Assets 列表。 然后我使用其中之一并在 MPMusicPlayerControll
我正在使用 Foundation Orbit slider 。它工作正常,只是我需要将一些 css(移动标题)应用于页面上的特定 slider 。 如果我使用以下选择器,它会进行更改,唯一的问题是它是
我最难搞清楚如何在 Foundation 的 Orbit slider 中制作两个文本元素和一个按钮。对于这样的初学者问题,我深表歉意,但我是 Foundation 的新手,有些语法让我感到困惑。 这
我需要来自 SoundCloud 的“最流行”或“ HitTest 门的轨道”,但我找不到任何方法来做到这一点。我可以从 http://api.soundcloud.com/tracks?filter
我刚刚从 Rails 3.2 切换到 Rails 4。我正在努力确保我尽可能了解安全问题,并且我现在担心 session 。看起来 Rails 4 已经不再支持除基于 cookie 的 session
我正在开发一个应用程序,用户可以在其中流式传输或下载视频。我使用 ExoPlayer 2.9.6 实现了相同的功能。目前,在播放下载的内容时,当我尝试切换质量时,它仅显示下载的轨道。我知道它的默认行为
有谁知道制作这样的标题的最佳方法 http://i.imgur.com/NOSF0.png ?我试过使用 Firebug 并实现了这个 http://i.imgur.com/cMB3Y.png但是当我
我正在使用 Zurb 轨道 slider :http://www.zurb.com/playground/jquery_image_slider_plugin 我使用以下设置进行幻灯片放映: $(wi
所以我们在这里:http://greeceinsiders.com/VLASIOS/offcanvas/studio.html 我按照说明在页面中放置轨道 slider ,但这个似乎不起作用。我从其他
我是一名优秀的程序员,十分优秀!