Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by fabianzaf · Apr 28, 2013 at 09:22 PM · quaternionaxisorientationreverse

Reverse Axis of Quaternion

Is it possible to reverse 1 axis of a Quaternion? Quaternion.Inverse reverses all the data.

Would you have to convert to Euler then somehow back to Quaternion?

I'm getting quaternion orientation data from an external source but the Z data needs to be reversed and I read you're not supposed to modify Quaternion data directly. (very difficult)

I dont want to use EulerAngles because of Gimbal Locking, would reprojecting it somehow (using Slerp?) fix that?

Thanks for any help in advance

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fabianzaf · Apr 28, 2013 at 09:25 PM 0
Share

Would it require the conversion of a matrix to a quaternion? Am I onto something?

avatar image whydoidoit · Apr 28, 2013 at 09:52 PM 0
Share

Are you receiving a quaternion or a euler angle?

avatar image fabianzaf · Apr 28, 2013 at 09:53 PM 0
Share

I'm receiving quaternion data over a protocol, X,Y,Z,W

avatar image whydoidoit · Apr 28, 2013 at 09:56 PM 0
Share

Then just invert the Z coordinate and it will be fine.

avatar image whydoidoit · Apr 28, 2013 at 09:57 PM 0
Share

Presu$$anonymous$$g you mean that the Z of the quaternion is inverted (not the Z of the resulting euler angle).

Show more comments

5 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by bderooms · Aug 12, 2013 at 06:19 PM

I believe (having experience with Kinect & Unity3d) that what he wants is the same Rotation in a coordinate space where Z is inverted. That comes down to mirroring around the XY plane. To mirror a quaternion around the XY plane, you need to negate the Z value and the W value.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JeremiahJ · Apr 26, 2018 at 02:10 PM 0
Share

Thank you. This is exactly what I was trying to do, and your simple explanation is everything I needed.

avatar image
2

Answer by Loius · Apr 28, 2013 at 09:59 PM

"The Z needs to be reversed"

Because quaternions are stupid hard to deal with, that statement may mean anything.

D'you want the character to face the other way? Rotate by 180 around the Y axis.

You can rotate a quaternion by multiplying it by another quaternion. Say A is your facing you want to change, and B is Quaternion.AngleAxis(Vector3.up,180) (or whatever the syntax is). If you want to rotate A by 180 around Y, then: A = B * A.

edit: As noted in the comments, you're perfectly free to alter the data in a quaternion. You just don't know what that will do, unless you do know what that will do. If you're getting bad z values, go ahead and fix 'em.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fabianzaf · Apr 28, 2013 at 10:19 PM 0
Share

The data I'm getting comes from a system where Z is up, in Unity Y is up, thats why I need to invert them.

Directly modifying the Z as "whydoidoit" creates unexpected results.

Created another quaternion and multiplying it with $$anonymous$$e also creates unexpected results... perhaps I'm just not understanding it correctly.

I hope I'm making some sense, this is a $$anonymous$$inect project, so his left arm is moving correctly other than the fact that he's moving his arm up when I move my arm down. (Due to the Z not being flippeD)

avatar image whydoidoit · Apr 28, 2013 at 10:22 PM 0
Share

That's not an inversion. It's always best to say what you want to do :D

You need to multiply it by something like:

      Quaternion.FromToRotation(Vector3.forward, Vector3.up);
avatar image fabianzaf · Apr 28, 2013 at 10:50 PM 0
Share

Not working, how am I supposed to use it exactly? This is a code sample for my right arm:

 private var leftShoulder : GameObject;
 var leftShoulderRigObj : GameObject;
 private var leftShoulderOrientation : Quaternion;
 
 
 function OSC$$anonymous$$essageReceived(message : OSC.NET.OSC$$anonymous$$essage ){    
         var address : String = message.Address;
         var args : ArrayList = message.Values;
 
     if(address == "/Left_Shoulder") {
 
         var first_Left_Shoulder : boolean = true;
         var second_Left_Shoulder : boolean = false;
         var third_Left_Shoulder : boolean = false;
         var fourth_Left_Shoulder : boolean = false;
     
         for( var item in args) {
             if (first_Left_Shoulder) {
                                             //Quaternion W
                                             leftShoulderOrientation.w = item;
                                             first_Left_Shoulder = false;
             second_Left_Shoulder = true;
             } else if (second_Left_Shoulder) {
                                             //Quaternion X
                                             leftShoulderOrientation.x = item;
             second_Left_Shoulder = false;
             third_Left_Shoulder = true;
             } else if (third_Left_Shoulder) {
                                             //Quaternion Y
                                             leftShoulderOrientation.y = item;
             third_Left_Shoulder = false;
             fourth_Left_Shoulder = true;
             } else if (fourth_Left_Shoulder) {
                                         //Quaternion Z
                                         leftShoulderOrientation.z = item;
                                                                     fourth_Left_Shoulder = false;
                         
             }
 
 leftShoulderRigObj.transform.rotation = Quaternion.Inverse(leftShoulderOrientation);
 

Every time I get an OSC message it runs this code and goes through a foreach loop ans saves XYZW in a quaternion, I then take that quaternion, inverse it and set it to the rotation of my gameobject in the scene.

I hope this gives some context, sorry I've been awake for 48 hours and been dealing with this problem for 7 days.. its ridiculous

avatar image whydoidoit · Apr 28, 2013 at 10:53 PM 1
Share

I was suggesting that you do:

   leftShoulderRigObj.transform.rotation = Quaternion.FromToRotation(Vector3.forward, Vector3.up) * leftShoulderOrientation;
avatar image
1

Answer by s_guy · Apr 29, 2013 at 12:48 AM

"Is it possible to reverse 1 axis of a quaternion?" I think you might be confusing the XYZ of a quaternion as being 3 axes, as with Euler angles. Instead, with quaternions, the XYZ describes a single axis that the rotation W is applied to.
wikipedia overview

It sounds like you mean to ask "Suppose someone had converted Euler angles to a quaternion, and that's all I have now. How do I get the quaternion for the same Euler angles with an inverted Z axis?"

If that's the case, you might try :

 Vector3 myEulerAngles = myQuaternion.EulerAngles();
 Quaternion myFixedQuaternion = Quaternion.Euler(myEulerAngles.x, myEulerAngles.y, -myEulerAngles.z);

Keep in mind that Quaternion.Euler "Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order)."

If you're after something different, it might help to diagram what you're trying to do.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by TravelLIN · Aug 22, 2017 at 07:40 AM

Guess in your case the answer is " * ". Try to do something like this:

 private Transform target;
 
 private void Update()
 {
     // get your target's rotation
     Quaternion targetRotation = target.transform.rotation;
     
     // choose an object and multiply its axis to reverse
     transform.rotation = targetRotation * Quaternion.Euler(0, 180f, 0);
 }



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by emthele · Jun 09, 2016 at 12:04 PM

His question is actually not that bad, and is fully understandable if you have ever worked with sensor data on your on. The point here is, IMU sensor data usually is calculated into quaternion data. This data can directly be applied to the GameObject Transform via euler angles:

 transform.eulerAngles = bodyQuaternion.eulerAngles;

where bodyQuaternion is the quaternion from the sensor data.

Now I create a simple Cube in unity and want it to behave like my sensor. Therefore, I have to exchange the quaternion values X and Y before. In my code, this looks like this:

 bodyQuaternion.w = imuSensor.Quaternion[0];
 bodyQuaternion.x = imuSensor.Quaternion[1];
 bodyQuaternion.z = imuSensor.Quaternion[2];
 bodyQuaternion.y = imuSensor.Quaternion[3];

Note the order: w, x, z, y.

With that, it works perfectly fine, except the fact that my view towards the sensor would be from "behind" in unity. Which means, if I turn it clockwise parallel to earth gravity axis (yaw), it turns counter-clockwise in Unity. I simply see it from the wrong side in my program. Therefore, I want to invert the view axis Z in unity.

As I'm also new to Unity, I have no idea how to do best: Local axis of my cube? Another rotation with another quaternion for 180 degrees? There were some good ideas above, and I will try them.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image emthele · Jun 11, 2016 at 01:53 PM 0
Share

Update: I managed to resolve my issue. Unfortunately, I can't give a detailed description about what worked and what not, because I struggled around with that a lot in the last hours and tried things forwards and backwards.

But the wrongly turning Yaw was actually turning right, but the code was wrong in general, because the method with

 transform.eulerAngles = bodyQuaternion.eulerAngles;

with bodyQuaternion = sensor Quaternion used the world's axes for rotation, not the cube's axes.

Anyway, I managed to move the cube exactly as my sensor. Here's the topic for it: http://answers.unity3d.com/questions/1201108/quaternion-from-imu-sensor-to-gameobject-orientati.html

avatar image theophilos01 emthele · Aug 01, 2018 at 04:22 PM 0
Share

@emthele Could you please spare some time to talk with me. I am doing something similar and get a lot of problems and I am time pressured for my dissertation. I believe you can help me out in a matter of seconds. If you can spare some time please post here and I can send you my email (I already posted a question on this but not got any response). Thank you very much in advance. Have a nice day.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotating multiple points in space. 0 Answers

Two-hand grabbing of objects in Virtual Reality 2 Answers

Camera Rotation Question 1 Answer

Orientation axis to rotation 0 Answers

Problem fixing quaternions 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges