Calculating 3d rotation around random axis

This is actually a solved problem, but I want to understand why my original method didn’t work (hoping someone with more knowledge can explain).

(Keep in mind, I’ve not very experienced in 3d programming, having only played with the very basic for a little bit…nor do I have a lot of mathematical experience in this area).

I wanted to animate a point rotating around another point at a random axis, say a 45 degrees along the y axis (think of an electron around a nucleus). I know how to rotate using the transform matrix along the X, Y and Z axis, but not an arbitrary (45 degree) axis.

Eventually after some research I found a suggestion: Rotate the point by -45 degrees around the Z so that it is aligned. Then rotate by some increment along the Y axis, then rotate it back +45 degrees for every frame tick. While this certainly worked, I felt that it seemed to be more work then needed (too many method calls, math, etc) and would probably be pretty slow at runtime with many points to deal with.

I thought maybe it was possible to combine all the rotation matrixes involve into 1 rotation matrix and use that as a single operation.

Something like:

 [ cos(-45)    -sin(-45)         0]
 [ sin(-45)     cos(-45)         0]      rotate by -45 along Z 
 [    0            0             1]

multiply by

 [ cos(2)          0       -sin(2)]
 [    0            1            0 ]      rotate by 2 degrees (my increment) along Y
 [ sin(2)          0        cos(2)]

then multiply that result by (in that order)

 [ cos(45)      -sin(45)         0]
 [ sin(45)       cos(45)         0]      rotate by 45 along Z 
 [    0            0             1]

I get 1 mess of a matrix of numbers (since I was working with unknowns and 2 angles), but I felt like it should work. It did not and I found a solution on wiki using a different matirx, but that is something else.

I’m not sure if maybe I made an error in multiplying, but my question is: this is actually a viable way to solve the problem, to take all the separate transformations, combine them via multiplying, then use that or not?

4

You can indeed compound (‘add up’) the rotations by multiplication.

I’d consider using Quaternions instead though. They’re much nicer to work with and they avoid problems with Euler type rotations (e.g. gimbal lock). You can plug in arbitrary axes of rotation, rather than worrying about X, Y, Z rotations. Quaternion compound rotations nicely — and if you have interactive 3D objects the user can spin etc., you’ll want to compound rotations.

Lots on the web about Quaternions, e.g.:

  • http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

  • http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer

  • https://stackoverflow.com/questions/8919086/why-are-quaternions-used-for-rotations

2

It’s been a while since I did much matrix maths, but I’m pretty sure your approach is valid.

Sounds like you need to reverse the order of the transforms when you multiply those matrices together. When you combine matrix transforms (of any sort) you always start with the last one and work backwards.

1

The problem you get by rotating the axis separately is that you can experience what is called ‘gimbal lock’, a state where the rotations on the separate axis make it overlap in a way that your calculations will not produce the desired effect because the separate calculations interfere with the end result due to overlap. The solution to this is to specify the axis in a vector and rotation expressed in the form of an imaginary number. The way to calculate this is to use
Quaternions.
all types of rotation calculation will eventually yield a 4×4 matrix, as this is always the required form for expressing the final transformation. This implies that you can indeed add up the calculations through multiplication, but as described before, the additions can interfere with each other in certain cases.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật