Web Development
  Home arrow Web Development arrow Part Three: Rotation About an Arbitrary Axis
Affiliate Promotion  
Blog Help  
Domain Name Tips  
How To  
Newsletter Marketing  
Online Business Help  
Search Engine Tricks  
Web Development  
Web Hosting  
Website Advertising  
Website Content  
Website Marketing  
 Webmaster Tools
 
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML to PHP 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
 
Password Strength
 
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Whois
 
Forums Sitemap 
Mobile Linux 
APP Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB DEVELOPMENT

Part Three: Rotation About an Arbitrary Axis
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2004-05-30

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT



    by: cprogramming.com

    Rotations in Three Dimensions
    Part Three:  Rotation About an Arbitrary Axis
    Written by: Confuted, with a cameo bySilvercord (Charles Thibualt)

    The previous method of doing the rotationsis called usingEuler angles.  It's probably the simplest way of doing rotations,but ithas some problems.  The biggest problem is called gimballock.  Youmay or may not have already encountered this if you wrote codeaccording to thelast tutorial.  If you encountered it and noticed it, withoutknowing whatit was, you may have spent hours trying to figure out where you wentwrong inyour code, carefully comparing every line of your code to the tutorial,tryingto find the difference.  If that happened, I'm sorry.  Thereisnothing wrong with your code; there is something wrong with themath.  Ifyou'll recall, I told you two very important things, which you probablydidn'tconnect in the last tutorial.  1) Matrix multiplication is notcommutative. A*B != B*A.  2) We generated matRotationTotalby doing matRotationX * matRotationY* matRotationZ.  If therewas nothing wrong with the math, you should have been able to do matRotationY*matRotationZ*matRotationX,or any other order, and gotten exactly the same results.  But youwouldn't.  This problem is the root cause of gimbal lock. Trying tovisualize this might blow your mind, so if you don't understand thenextparagraph, don't worry too much.  Just remember that Gimbal Lockhappenswhen one axis gets rotated before another axis, and the axes are nolongermutually perpendicular.  It can be a large problem, or it can gounnoticed, depending on the application.

    We multiplied our matrices in the ordermatRotationX * matRotationY *matRotationZ.  It seemed to work, and for the most part, itdid. But if you think about it carefully, you'll realize that, as you movean objectin 3d space, all three axes change at once.  They remain mutuallyperpendicular to one another.  In the program, however, we'rerotating theobject over the X-axis first.  That rotates the Y andZ-axes.  Thenwe rotate over the Y axis, but since we've already rotated over theX-axis, therotation on the Y-axis only changes the location of the Z-axis. Therotation of the Z-axis does not change the location of either of theother twoaxes.  Huge problem if you need to rotate on all three axes,because oneaxis can literally end up on top of another axis!  (Just in themath.  It can't do that in real life, meaning our representationis notaccurate)

    Luckily for you, many math geniuses have dealt with this problem. Therewas a famous man named Euler, whom you'll hear mentioned inCalculus.  Hedetermined that any series of rotations in three dimensional space canberepresented as a single rotation over an arbitrary axis.  For thisrepresentation, called angle/axis representation, you'll need to storethearbitrary axis about which you are rotating, and the amount by whichyou arerotating.

    Now for the cameo by Charles, who was kind enough to write thefollowingsection for me:

    Arbitraryaxis rotation by Charles Thibault

    I am going to describe the calculations I perform in order to performrotationsabout an arbitrary axis.  These calculations are NOT the matrixform ofthe rotations.  Up to this point you know you can combine matricesinto asingle transformation.  The single transformation matrix involvesabout 29multiplication operations and 9 addition operations, whereas completelyrotating a vector using my transformations (meaning calling myRotateVectorfunction TWICE, once over the Y axis then once over the Strafe vector)entailsabout ten percent more multiplications and about twice as many additionoperations (32 multiplications for two RotateVector calls, and 18additionoperations for two RotateVector calls).

    How do you actually perform a rotation about an arbitrary axis? Wellfirstly you must understand rotations in two dimensions, because theconceptstays the same on an arbitrary plane.  I'm going to make this asshort andsweet as possible.  Instead of rotating the X and Y components ofavector, the X is really the component of the vector you are trying torotatePerpendicular to the vector that is the normal to the plane. Likewise theY is really the cross product between the vector you are trying torotate aboutand the actual vector being rotated. 

    Steps to rotate a vector:
    -Calculate the Perpendicular component, multiply it by the cosine ofthe angleyou are trying to rotate through
    -Calculate the cross product between the vector you are trying torotate aboutand the vector you are rotating, multiply it by the sine of the angle
    -Add the results together
    -Add the component of the vector you are trying to rotate that isparallel tothe vector you are rotating about

    Note it is not totally necessary to calculate the parallel component ifthevector you are rotating and the vector you are rotating about arealreadyorthogonal.  I do it in all cases anyway to avoid any mishaps andmakesure it is mathematically correct, but it seems to work bothways.  Plus,by leaving it in the code you can rotate vector A about vector P evenif A andP are not orthogonal.  (orthogonal means mutually perpendicular tooneanother)

    ContactSilvercord onCProgramming.com if you have questions about that section.  Therest ofthis will, once again, be written by me (Confuted).

    There's still the problem of performing the actual rotation about yourarbitrary axis.  Luckily, this can also be done with amatrix. Again, I'm not going to derive it, I'm going to spoon feed it toyou. You can thank me later.

    LeftHanded *

    RightHanded *

    tX2 + c

    tXY - sZ

    tXZ + sY

    0

    tXY+SZ

    tY2 + c

    tYZ - sX

    0

    tXZ - sY

    tYZ + sX

    tZ2 + c

    0

    0

    0

    0

    1

    X2 + c

    tXY + sZ

    tXZ - sY

    0

    tXY-sZ

    tY2 + c

    tYZ + sX

    0

    tXY + sY

    tYZ - sX

    tZ2 + c

    0

    0

    0

    0

    1

    Wherec = cos (theta), s = sin (theta), t = 1-cos (theta), and <X,Y,Z>is theunit vector representing the arbitary axis

    Now, you can replace matRotationTotal with thismatrix, and completely eliminate matRotationX, matRotationY, and matRotationZ. Of course, there is extra math involved elsewhere.  But by usingtheaxis/angle representation for your rotations, it is possible to avoidgimballock.  However, it's also possible to still suffer from it, if youdosomething incorrectly.  In the next tutorial, I'll talk about someof theuses for the things I've been saying, and after that, brace yourselffor theexciting and strange world of quaternions.  If you don't have aheadachefrom thinking too much yet, you probably will after the quaternions.
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Web Development Articles
    More By Developer Shed

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Best practices for software analysis: An introduction to the IBM Rational Software Analyzer application

    This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer.
    FREE! Go There Now!


    NEW! Integrating XML into Your Enterprise Using Data Federation

    XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services.
    FREE! Go There Now!


    NEW! The dirty dozen: preventing common application-level hack attacks

    As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! Cook up Web sites fast with CakePHP, Part 4: Use CakePHP&apos;s Session and Request Handler components

    CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

       

    WEB DEVELOPMENT ARTICLES

    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?
    - Build a Completely Free Site
    - Is Your Site Secure?
    - What`s So Special About Your Site?
    - Add Games to Your Site
    - Should You Offer E-mail?
    - The Trouble with CAPTCHA
    - Add Images Responsibly
    - Is There a Science to Site Design?
    - Shortcuts for Page Design
    - Rebranding a Community
    - Firebug Firefox Extension Review
    - Is a CMS or Custom Code Better for Your Web ...

     
    Create the Optimal Architecture for your Critical Applications
    Warburton's the largest independently owned bakery in the UK faced a number of d....

     
    Five Best Practices for Deploying a Successful Service-Oriented Architecture
    This white paper describes the benefits you can expect with SOA, and how IBM can....

     
    Gartner Magic Quadrant for Application Delivery Controllers
    Gartner summarizes its view on Application Delivery Controllers, evaluates stren....

     
    Knowledge is Power
    What you don't know can hurt you, and is likely costing you money and increasing....

     
    Rationalizing the Multi-Tool Environment
    The rationalized multi-tool approach is flexible, scalable and cost effective. I....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT