Replacing the Quaternion

Hello Folks, this post might be dramatic, but I think:

Let’s throw the Quanternion in the Trashbin.

I would really wish we had a simple Direction Vector3 with and additional roll angle. Easy to set up in the Editor and workable, unlike the Quaternion.

What do you think?

All Feedback Welcome, I don’t want to only discuss necessity, but more importantly Usability, every Contribution welcome.

Bye :wink:

lets take it back out of the trashbin, dust it off and apologise for putting it there in the first place and thank it for it’s tireless work at prevent gimbal lock and other such horrid things.

You can easily convert a Vector3 representation of a rotation to a quaternion with the variety of “Euler” and “EulerAngles” functions provided on both the Vector3 and Quaternion classes.

5 Likes

Or let’s spend some time learning why Quaternions are necessary, what problems they solve, and why they are the right tool for the job. You don’t have to understanding the math behind them to use them.

1 Like

Nope.

Pitch Yaw Roll is great for representing orientation, but complete balls for describing CHANGE in orientation.

And this is the part where most people screw up with Quaternions IMO… A Quaternion is not an orientation, it’s a CHANGE in orientation. Just like a Vector has magnitude and direction, so too does a Quaternion. It’s direction is an axis around which to rotate (not a static x,y,z axis… but any axis you want), and an amount of rotation around that axis. If you have no rotation around any axis, you have no rotation, this is the whole amount of change aspect.

Of course you might say “why don’t we store an axis and a angle then? It’s the same number of digits (4)…” True, BUT Quaternion’s ALSO come with arithmetic operations for appending and inverting, which is extremely useful.

Of course, if you want to show up William Rowan Hamilton and invent a better mathematical construct than the Quaternion… go for it. You would certainly garner huge amounts of fame in the math community.

2 Likes

Or let’s stop repeating what others keep on telling and discuss the Idea.

Same as Dave. (Please make up your mind, and stop shooting before you think, if that would ever be your Intention…) My Idea would also prevent gimbal lock, and actually is way more usable… your turn now…

Let’s keep it a Discussion. IF my solution is WORSE, tell me. Otherwise we would want to give it a try, that’s all…

What is easier than a Vector3 of Orientation Change? as well as another float describing the personal roll change? I don’t think you got my Idea…

Listen:

Think about a normalized Vector3 that just describes the facing. What is missing now, is the roll angle. Which acutally is the tricky thing, Because: what roll angle do you have when facing right? Left? Up? Down? Forward Left Down? Must there be a standard rotation? A normal always trying to face up?

That is the question and discussion I would like to see. Please, stop foiling progress and start to contribute.

Don’t get me wrong, I don’t want to screw up Hamilton. I just think there must be a better solution.

So what’s stopping you giving it a try?

2 Likes

When you say:

By ‘direction’ and ‘roll’, do you mean a axis and amount of rotation around that axis?

Because if you read my post, you’d know I said that IS what a Quaternion is pretty much (sort of, it’s the easiest way to conceptualize it). The major benefit of a Quat over angle/axis, is that Quat’s also have simple and efficient arithmetic operations to append and invert Quats.

And remember, Quaternion has methods to convert to and from angle axis:
from angle axis:

to angle axis:

You could just write your own Struct if you want to store the angle-axis for in the editor, but has a conversion to Quaternion for easy on the fly conversion.

Okay…

What is the problem with using a quaternion in the editor? I’ve never once had to think about it - add an object to the screen and rotate it to where I want. Don’t even care about any numbers, just the visual orientation I see. I don’t now how moving away from quaternions would provide any different behavior from what is used now.

And what about all of the other nice behavior you get with quaternions as mentioned by @lordofduct ? In particular slerp for smoothly rotating orientation? I’ve forgotten the math involved in doing that sort of thing with with axis/angle, but if I remember right it involved matrices and small rotations and orthonormalization and fun things like that. Those problems just don’t seem to exist with quaternions.

Also there’s nothing stopping you from creating a custom editor to do what you want with the vector and roll angle if that’s how you want to edit your orientation.

Not all feedback apparently. :stuck_out_tongue:

2 Likes

Well, I made a fair argument, so that has to be ignored as it deconstructs their own narrative…

that or my infamy preceeds me and they pre-emptively ‘ignored’ my account.

1 Like

I was giving OP the benefit of the doubt on that since it had only been a few minutes - surely they’re typing up a response as we speak.

@dCalle , as @lordofduct is telling you, a quaternion IS a direction and a “roll” angle (sort of). It’s just in a form that makes operations straighforward. If you discard quaternions, how would you combine rotations? How do you even rotate a single vertex without quaternions? What more efficient alternative do you propose?

Unity Sourcecode… And I’m definitely not trying to convert Quaternions^^… yet

Am currently doing it that way but I would rather use Vector3s the whole time instead of switching from and to Quaternion.

Still it seems my Solution really has problems with a clear rotation…

Well if a 3D Space Dog Fight would be just about placing Gameobjects^^

OR some people just need their time to answer :wink:

:wink:

Well I guess " A peasant won’t eat what he doesn’t know" fits me quite well^^

So I just stick to my Failure and come back when I either found a Solution for the problem of my solution, or coincidentally am going to like the quaternion for what it is, after every doubt is cleared…

Thanks for your eager participation. You are doing quite well, and I am sometimes but a son of a bitch :wink:

Nighty :wink:

You don’t need Unity’s source code to try this.

1 Like

How about explaining exactly what problems you’re having using quaternions?

2 Likes

Allow the conversion to be implicit…

using UnityEngine;

public struct AxisAngle
{

    private Vector3 _axis;
    private float _angle;

    public AxisAngle(Vector3 axis, float a)
    {
        _axis = axis.normalized;
        _angle = a % 360f;
        if(_angle < 0f) _angle += 360f;
    }

    public AxisAngle(Quaternion q)
    {
        Quaternion.ToAngleAxis(out _angle, out _axis);
    }

    public Vector3 Axis
    {
        get { return _axis; }
        set { _axis = value.normalized; }
    }

    public float Angle
    {
        get { return _angle; }
        set {
            _angle = value % 360f;
            if(_angle < 0f) _angle += 360f;
        }
    }




    public static implicit operator Quaternion(AxisAngle aa)
    {
        return Quaternion.AngleAxis(aa.Angle, aa.Axis);
    }

    public static implicit operator AxisAngle(Quaternion q)
    {
        return new AxisAngle(q);
    }

    public static AxisAngle operator +(AxisAngle a, AxisAngle b)
    {
        var q = (Quaternion)a;
        q *= (Quaterion)b;
        return new AxisAngle(q);
    }

    public static AxisAngle operator -(AxisAngle a, AxisAngle b)
    {
        var q = (Quaternion)a;
        q *= Quaternion.Inverse((Quaternion)b);
        return new AxisAngle(q);
    }

    public static AxisAngle Slerp(AxisAngle from, AxisAngle b, float t)
    {
        return new AxisAngle(Quaternion.Slerp((Quaternion)a, (Quaternion)b, t));
    }

}

With something like that you can just throw Quats and AxisAngles together. Since it’s an implicit conversion, the compiler will know what to do whenever you go and say try to assign a AxisAngle to the rotation property of something.

You could even go and define append, slerp, invert, etc operators as well, encapsulating the conversion, so you can do everything in this (I included 2 examples + and Slerp).

It of course will be a bit slower…

And of course you’ll probably want to go and write a custom editor for it to assist with the axis field. You could also make those field public, I merely made them private so as to validate passed in values.

But yeah… then you could just say things like:

AxisAngle a = transform.rotation; //I can't recall if C# allows implicit conversion in this scenario... might have to explicitly place (AxisAngle) on front
a += new AxisAngle(Vector3.up, 10f);
transform.rotation = a;

I still think it’s a lot of hoo-ha for no real reason. Might as well just use quats.

I mean heck… is this that different from this:

var a = transform.rotation;
a *= Quaternion.AngleAxis(10f, Vector3.up);
transform.rotation = a;

I mean, really, where is this AngleAxis all that useful other than an editor view? Where you don’t want the editor to display euler angles, but rather angle axis. In which case… you could write a custom PropertyDrawer to handle that, no need for this runtime AngleAxis slow conversion back and forth.

And as was explained earlier, you’re going to want to use the quat for the arithmetic for slerp, appending, inverting, etc… because doing it with angle axis directly is SLOW, the math is far more complicated than with the simple quaternion operators. This is WHY quats are so preferred these days… they’re actually really easy once you wrap your head around the very simple “amount of change in rotation” part. The only nuisance is DISPLAYING the quat in a human readable sense… and that’s just an editor script away, it just happens unity prefers to show quats in euler in the editor rather than angle axis.

4 Likes

So hoping this is a troll post considering it was dCalle’s first post.

If it is a sincere post however, @dCalle , how ready are you to fight centuries worth of math? Did you even find out what a quaternion is and how it’s derived and used compared to your own method to make sure your own method is genuinely better and has accounted for all scenarios? You have not really explained at all how your method is supposed to work either which makes your case far less convincing.

How are you going to re-write quaternion’s when you obviously don’t understand them?

3 Likes

hey folks, thanks for showing me off, I actuallygot a bunch of problems with quats and stuff, and @lordofduct is definitely beyond my reach. Also @Dave-Carlile thanks for the Question, maybe help is what I need the most…although I’m acting like a bitch^^

@JamesLeeNZ I wouldn’t and obviously I have to excuse my overall haughtiness… still I have to ask why you are posting this with such an obvious intention? Maybe because your sick of those inept, which I can understand and I’m really sorry home :wink:

Still thanks to all of you, I am going to rephrase all my insults to the quaternion as humble questions from a stupid unknowing mind unable to grasp the abstract mathematical world. yet

Can I still count on your help? I am willing to learn I am just a bit frustrated from some dive in complexity…Still I appreciate the supporting community, didn’t want the piss it off but try to inspire and find a better solution than those “centuries worth of math”. A Sacrileg I got to know^^ I just think I’m misunderstood :wink:

definitely got to tell this story in some years from now :wink:

May I still post questions with this account or am I already demonized?^^

2 Likes

You’re welcome to ask any question you want.

This isn’t a matter of what you’re allowed to say, you were more than allowed to say that you don’t like quats.

Just that people may respond to that with a “huh? why? you’re probably mistaken in some way.”

So yeah, go ahead, ask away.

1 Like

I can’t think of any reason why anyone would demonize your for trying to think of a better way to do something, even if that better way may not actually be better. :p. Approach is everything though, so starting with questions is probably going to work out better for you.

But in some places my user name is “dcarlile”, which makes your account name very confusing because I keep momentarily seeing people quoting me as saying things I don’t remember saying. So yeah, you should really change it. (no, not really).

1 Like