Creating Left handed coordinate system

Started by
34 comments, last by Fulcrum.013 5 years, 6 months ago

While ago I started to create my own simple math library in C++. I created my vectors, matrices and their operations like dot, cross, translations and rotations. I used all of it as I learned it from math classes. I got curious and wondered which system it is. Since it's a general system "usually thought" I think its a right-handed coordinate system.

What really makes a system left or right coordinate system? What would I need to change in my library to make it left-handed? Does the cross product function needs to change or is something in the matrices?

Advertisement

What makes the system left-handed is your interpretation of what the x, y, and z coordinates mean when you visualize the vectors. The arithmetic is independent of handedness, so there is nothing in the library that depends on it.

 

5 hours ago, alvaro said:

What makes the system left-handed is your interpretation of what the x, y, and z coordinates mean when you visualize the vectors. The arithmetic is independent of handedness, so there is nothing in the library that depends on it.

 

I'm a bit confused, when someone says that DirectX and Unity3D use a left-handed and OpenGL uses right-handed, what is actually different?
So you are saying that we could for e.g. think of DirectX as right-handed and that everything would work?

Quote

I'm a bit confused, when someone says that DirectX and Unity3D use a left-handed and OpenGL uses right-handed, what is actually different?
So you are saying that we could for e.g. think of DirectX as right-handed and that everything would work?

Neither modern Direct3D nor modern OpenGL enforce any particular handedness. You can use a left- or right-handed coordinate system with either.

The fact that they're often described as being left- and right-handed, respectively, is I think largely for historical reasons. I'm not sure about DirectX/Direct3D off the top of my head, but if you go back to early versions of OpenGL you find a few utility functions that assumed a right-handed coordinate system. Even in early versions of OpenGL though there were functions that allowed for submitting arbitrary transform matrices (or you could just transform everything yourself), so even then I think you could use whatever handedness you wanted.

A possible point of confusion is that depending on the conventions used, it may be necessary to flip along the z axis as part of the transformation to clip space. This leads to the 'left-handed' and 'right-handed' projection matrices that you'll commonly see, which is one of the few places handedness can be directly relevant in a math library. The only other place I can think of is so-called 'look at' transforms. In early versions of OpenGL there were utility functions for both of these transform types, and these functions used a right-handed convention, which may be the main (perhaps only) reason OpenGL is often thought of as being 'right-handed'.

As an example of what I'm talking about, you can look at the DirectX matrix functions listed here:

https://docs.microsoft.com/en-us/windows/desktop/dxmath/ovw-xnamath-reference-functions-matrix

You'll note that all the functions that have LH and RH versions deal with projection or 'look at' transforms. There are no LH/RH versions for transforms such as rotation because, as alvaro said, the mathematics of those operations is independent of handedness.

I'm still having a hard time to understand this. When I used to program in Unity3D and for e.g. if I would put a GameObject in front of me, in front of the camera, x-axis would be pointing to the right, y-axis to up and z-axis away from me. I knew that if I wanted to apply a rotation to it around x-axis, y and z would rotate away from me.
Now, for a right-handed coordinate system it's a completely another story, x-axis would be pointing to the right, y-axis to up and z-axis towards me. Rotation around x-axis would rotate toward me. So this is a lot different from the first case that I described.
These two cases don't use at all some functions analog to LH/RH versions and yet the system behaves differently.

I think that something else has to be that drives those differences. Maybe I just confused something but I don't understand what? 

1 hour ago, fleabay said:

Use your left hand for a left handed system. Point your thumb down the positive x-axis. Your fingers curl in the positive rotation. You can also point your thumb down the positive y or z axis and the fingers also curl in the positive rotation for that axis.

That's what I did for my example, I don't understand where is this in the code defined, what makes it to use "away" or "toward" facing z-axis and what tells you to use your left/right hand and curl your fingers?
If it's let's say left-handed system and you use your right hand and curl the fingers you'll get wrong results.

The thing is, lets say you come to some system for e.g. Unity3D and you don't know that is uses left-handed coordinate system, how could you tell it's a left one if you don't look into the documentation, what defines it?

On 9/28/2018 at 1:58 PM, ryt said:

What really makes a system left or right coordinate system?

It is a sign of cross production. For right coordinate system it is  + before result for left it is -.

#define if(a) if((a) && rand()%100)

1 hour ago, Fulcrum.013 said:

It is a sign of cross production. For right coordinate system it is  + before result for left it is -.

Yeah if you have right-handed system, if you have the opposite than the same holds for left-handed system.

But that was not kinda my original question. I wanted to know how could I tell by merely looking at the system or if you create one how do you choose.

1 hour ago, fleabay said:

Lets say we have 3 Axis. The first axis can point any direction. Let's say it points right. Now we have a second axis. It needs to be perpendicular (90%) to the first for our Cartesian system. For convenience let's say it points up but there is a whole range around the x axis it could point. Now the third axis can point in only one of 2 directions to maintain the 3D Cartesian grid. Toward us or away from us. These 2 possibilities had to be called something. Someone noticed you could use your left and right hand to differentiate between the 2 and thus they were named as such.

Ok, but how do you choose between these 2 possibilities, where is that written? If you start creating your library and you want for e.g. to choose the first one, how do you define that, where is your mathematical expression and code for this?

This topic is closed to new replies.

Advertisement