How do I calculate x, y, z velocity given two rotation angles and a speed?

Another way of saying this question: How do I find the length, width and height of a cuboid given it's diagonal length and 2 rotational angles.

This is for a 3d game where the user can change up/down rotation (UP and DOWN arrow keys), left/right rotation (LEFT and RIGHT arrow keys) and the object can accelerated and reverse (Q and w). Each frame, the objects x, y, z gets updated according to it's current speed and up/down and left/right rotation.


If alpha is the left/right angle and beta is the up/down angle, then

v.x = speed * sin (alpha) * cos(beta)
v.y = speed * sin (beta)
v.z = speed * cos (alpha) * cos(beta)

Assuming, that no rotation will return the direction (0, 0, 1)

I'm assuming that this cuboid is measured using a static frame of reference, where the diagonal starts at the origin and extends to some other point. If not, this question has no definitive answer, as a diagonal length alone can not determine the width, height and length of some arbitrary cuboid, as there are an infinite number of cuboids that could have the same diagonal.

It sounds like what you're using is a spherical coordinate system:

From the article:

x = r sin θ cos φ
y = r sin θ sin φ
z = r cos θ

r is your diagonal length. You'll have to determine θ and φ based on your rotation angles; they may not be proper inclination and azimuth angles. See the article for details on how these angles are defined in spherical coordinates.

Need Your Help

findViewById within fragment

android android-fragments findviewbyid

Is there any way to find a view by id within the scope of a fragment? I'm using a series of fragments to render a specialized list. The fragments are loaded from a layout, so their widgets all ha...

JPA: persisting entity with composite primary key

java hibernate jpa

I have two tables in database, A and B. Table B has an id composed of two fields. One of them is a foreign key to A. Id of A is automatically generated on insert by a sequence.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.