Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6974875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:17:39+00:00 2026-05-27T17:17:39+00:00

it seems that there is a problem with my custom Quaternion implementation. Download My

  • 0

it seems that there is a problem with my custom Quaternion implementation.
Download My quaternion implementation in Java.

When I lauch this snippet, in order to see quaternion angle evolutions, in a Main() method :

    Quaternion currentRotation = Quaternion.buildIdentityQuaternion();
    Quaternion constantRotation = Quaternion.buildFromAxisAngle(10, 0,1,0);

    while(true){
        float angle = currentRotation.toAxisAngle()[0];
        System.out.println(angle);
        currentRotation = constantRotation.mulInLeftOf(currentRotation);
    }

I’ve got the following results :

0.0
9.99997
19.999975
29.999979
39.99998
49.999977
59.999977
69.99998
79.99997
89.99997
99.99997
109.99997
119.99997
129.99997
139.99997
149.99997
159.99997
169.99997
179.99997
189.99998
199.99998
209.99998
219.99998
230.0
240.0
250.00002
260.00003
270.00003
280.00003
290.00006
300.0001
310.00012
320.00015
330.00024
340.00037
350.00082
360.0
350.00012
340.0001
330.0001
320.0001
310.00006
300.00006
290.00006

So why does the angle value first goes to 360 degrees then decreases toward 0 ? Though I’ve computed the angle with the formula 2*Acos(Quaternion.w) in Quaternion#toAxisAngle() method ? Maybe the implementation is not bad, so how can I compute the angle so that it returns 0, 10, …,350, 360, 0, 10, …, 350, 360, 0, 10 and so on ?

And finally, is there a way to compute the real angle ? SO that angle goes across values : 0,10,20,30,…,360,0,10,20… ?


However I managed to use it in a JOGL program to make a Simple 6-color cube rotate regularly, simply by computing a quaternion multiplication each time and by calling toMatrix() method on the result quaternion. What worked (do not pay attention to JOGL specific implementation details) :

  // The OpenGL functionnalities of my program
  MyJOGLEventListener implements GLEventListener {

       Quaternion myCurrentRotation = Quaternion.buildIdentityQuaternion() // w=1, x=0, y=0, z=0
       Quaternion constantRotation = Quaternion.buildFromAxisAngle(0.02f, 0,1,0) // angle = 0.02 degrees, x=0, y=1, z=0

       GLUgl2 glu = new GLUgl2();

       public void display(GLAutoDrawable drawable) {
            GL2 gl = drawable.getGL().getGL2();
            gl.glClear(/* OMITTED : color buffer and depth buffer*/);
            gl.glLoadIdentiy();

            glu.gluLookAt(/* OMITTED */);

            /// the three most relevent lines ///////////////////////////////////
            gl.glMultMatrix(myCurrentRotation.toMatrix(), 0);

            MyCubeDrawer.drawCube(gl);

            myCurrentRotation = constantRotation.mulInLeftOf(myCurrentRotation);
            //////////////////////////////////////////////////////////////////////

      }

     // OMITED : in init(GLAutoDrawable) method, I set up depth buffer
     // OMITED : the reshape(GLAutoDrawable drawable, int x, int y, int width, int height) sets the viewport and projection
 }

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:17:40+00:00Added an answer on May 27, 2026 at 5:17 pm

    I suspect that your quaternion implementation is fine. When you pass 360 degrees with a quaternion, it inverts the axis of rotation. So at first, your quaternion represents positive rotations around the positive y axis; however, once you cross 360 degrees, it begins to represent a positive rotation around the negative y axis.

    So the angles you are getting are still correct. A rotation of zero is usually represented as [1 0 0 0]. A rotation of 180 degrees around the y axis will be represented as [0 0 1 0]. And then a rotation of 360 degrees (obviously equivalent to a rotation of 0) comes out to be [-1 0 0 0]. Rotating by another 180 degrees will give you [0 0 -1 0] This is a general property of quaternions. They’re 2x redundant. If you negate all the components of the quaternion, it’s equivalent to rotating the opposite direction around a flipped axis to get the same result.

    To get what you wanted, you could just check the y component of your quaternion. If it’s less-than-zero, then subtract your computed rotation from 360 in order to flip the axis back to positive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some easy way to pad Strings in Java? Seems like something that
It seems that there has been a recent rising interest in STM (software transactional
It seems that there are several really fast prime factorization algorithms around (one that
After looking at RescueTime for windows/mac, it seems that there's a version for linux
How can I add an URL to the trusted site? It seems that there
I know, I know, its sounds silly, but it seems that there are no
It seems to me that there are two scenarios in which to use JOINs:
I've noticed that there seems to be quite a bit of hostility towards Linq
It seems that these two operators are pretty much the same - is there
I have a Flex application that seems larger than it should be. There is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.