June 18th, 2013, 04:45 AM

3D coordinate problems
Hi everyone I have a problem that I’m trying to figure out the best way of solving.
I have two systems which use two different 3D coordinate systems system 1 has +Y going up, +Z going away (forward in the system if 0,0,0 is the origin) and +X going to the right. System 2 has +Z going up, Y going away (again, forward in the system) and +X going to the right.
System 1 is in Pyhon with system 2 being a Haptic renderer in C++ (both systems in meters). However I need to translate/rotate objects in 3D from system 1 to be sent into system 2 (probably by two methods a system12Translate method and a system21Translate method). Once translated etc I can send the coordinates via a string to system 2.
I’m currently working on a few ideas, but if I could have any pointers that would be great, thanks!
June 18th, 2013, 05:08 AM

Perhaps I miss understand the situation, but the coordinate transformation from system 1 to system 2 seems obvious.
system 1 has +Y going up, +Z going away (forward in the system if 0,0,0 is the origin) and +X going to the right. System 2 has +Z going up, Y going away (again, forward in the system) and +X going to the right.
Can't you just transform your system 1 coords to system 2 simply by switching your y and z coordinates?
i.e. (x1,y1,z1) > (x2,y2,z2)
x2 = x1
y2 = z1
z2 = y1
As for things like rotations, it might be easier to do these in system 1 and then transform the result into system 2 via the above approach.
Like I said before, that seems too simple. I must be misunderstanding.
June 18th, 2013, 10:10 AM

Thanks, I've tried that before with no luck but I'll give it a think and come back.
June 25th, 2013, 04:09 AM

Originally Posted by MODDOM
Perhaps I miss understand the situation, but the coordinate transformation from system 1 to system 2 seems obvious.
Can't you just transform your system 1 coords to system 2 simply by switching your y and z coordinates?
i.e. (x1,y1,z1) > (x2,y2,z2)
x2 = x1
y2 = z1
z2 = y1
As for things like rotations, it might be easier to do these in system 1 and then transform the result into system 2 via the above approach.
Like I said before, that seems too simple. I must be misunderstanding.
If I do the transforming as above which is still confusing since the coordinate systems are so different, I take it I would also have to perform the scaling at the same time since the size between the two systems differ. I also need to do the oppose from System 1 to System 2 when the data gets set back.
June 25th, 2013, 04:28 AM

From what I understand, system 2 is obtained if system 1 is rotated +90 degrees along the xaxis, in which case, you will get coordinates of system2 if you multiply coordinates of system1 with a conversion matrix:
Code:
_ _ _ _ _ _
 x2   1 0 0   x1 
 y2  =  0 cos(90) sin(90)  x  y1 
_ z2 _ _ 0 sin(90) cos(90) _ _ z1 _
If you can write a function to multiply these matrices, then you will get the coordinates in system2.
Last edited by noobie1000; June 25th, 2013 at 04:31 AM.
June 25th, 2013, 04:34 AM

Originally Posted by noobie1000
From what I understand, system 2 is obtained if system 1 is rotated +90 degrees along the xaxis, in which case, you will get coordinates of system2 if you multiply coordinates of system1 with a conversion matrix:
Code:
_ _ _ _ _ _
 x2   1 0 0   x1 
 y2  =  0 cos(90) sin(90)  x  y1 
_ z2 _ _ 0 sin(90) cos(90) _ _ z1 _
If you can write a function to multiply these matrices, then you will get the coordinates in system2.
Many thanks, I'll try that now and come back.
June 25th, 2013, 05:03 AM

Remember that the conversion matrix will change depending on the axis and angle of rotation. I don't remember much of it.. I just remember studying it back in engineering years ago.
June 25th, 2013, 05:25 AM

Originally Posted by noobie1000
Remember that the conversion matrix will change depending on the axis and angle of rotation. I don't remember much of it.. I just remember studying it back in engineering years ago.
Thanks, I am having to go back and relearn all the stuff I have forgotten.
I used numpy to multiply between the matrices:
Code:
import math
import viz
from numpy import *
viz.go()
trans_matrix = array( [ (1,0,0), (0,math.cos(90),math.sin(90)), (0,math.sin(90),math.cos(90)) ] )
Vz_Coordinates = array( [0,1.332,0] )
Hm_Coordinates = dot(trans_matrix,Vz_Coordinates)
print Hm_Coordinates
Which gave me this:
Code:
[ 0. 0.59683406 1.19080356]
Which needs to be scaled but is correct in terms of coordinates etc.
I'll have to work on the scaling and as you said double check on the angles etc
June 25th, 2013, 05:28 AM

I also guess that reverting back from system 2 to system 1 coordinates is a matter of simply rotating the x axis back 90 degrees.
June 25th, 2013, 06:12 AM

Originally Posted by HapticMan
I also guess that reverting back from system 2 to system 1 coordinates is a matter of simply rotating the x axis back 90 degrees.
Yes, that's right. In general, you just need to figure out the right conversion matrix for corresponding axisangle combination.
June 25th, 2013, 10:53 AM

It is quite possible I am wrong (and if I am, please tell me). But does it not seem strange that you take a vector which lies along the yaxis (i.e. (0, 1.332, 0)) and rotate it by 90 degrees and get:
[ 0 0.59683406 1.19080356]?
If you were to take a vector (1,0,0) and rotate it about either axis by 90 degrees wouldn't you get either (0,+/1,0) or (0,0,+/1)? How come you rotate a vector, which starts on an axis, by 90 degrees and somehow it ends up between the y and z axes?
Like I said. Perhaps there is something simple I overlooked, but that answer doesn't seem right to me.
June 25th, 2013, 08:28 PM

Agree with MODDOM. On paper the following matrix multiplication
Code:
_ _ _ _
 1 0 0   0 
 0 cos(90) sin(90)  x  1.332 
_ 0 sin(90) cos(90) _ _ 0 _
gives
Code:
_ _
 0 
 0 
_ 1.332 _
@HapticMan: Please recheck the numpy function you used for matrix multiplication. I haven't worked on numpy, so I have no idea about that. As a suggestion (and a good exercise ): why not write your own function for matrix multiplication.
June 26th, 2013, 04:46 AM

Originally Posted by noobie1000
Agree with MODDOM. On paper the following matrix multiplication
Code:
_ _ _ _
 1 0 0   0 
 0 cos(90) sin(90)  x  1.332 
_ 0 sin(90) cos(90) _ _ 0 _
gives
Code:
_ _
 0 
 0 
_ 1.332 _
@HapticMan: Please recheck the numpy function you used for matrix multiplication. I haven't worked on numpy, so I have no idea about that. As a suggestion (and a good exercise
): why not write your own function for matrix multiplication.
Thanks guys, I've double checked on paper too. I'll use the numpy cos/sin functions. I'm using the math package for those atm.
June 26th, 2013, 05:25 AM

I just realised what the problem is... the maths module in python needs an angle in radians, not degrees. In other words you need to do:
Code:
math.sin(theta_deg*math.pi/180)
And the equiv. for cosine.
June 26th, 2013, 05:30 AM

Originally Posted by MODDOM
I just realised what the problem is... the maths module in python needs an angle in radians, not degrees. In other words you need to do:
Code:
math.sin(theta_deg*math.pi/180)
And the equiv. for cosine.
Thanks, I've spent about 10 mins going round in circles wondering why that was happening before looking at the documentation. Painful that I have to convert. I can solve it easy on paper but numpy is being a pain!