Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0

    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!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    40
    Rep Power
    11
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    Thanks, I've tried that before with no luck but I'll give it a think and come back.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    From what I understand, system 2 is obtained if system 1 is rotated +90 degrees along the x-axis, in which case, you will get co-ordinates of system2 if you multiply co-ordinates 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 co-ordinates in system2.
    Last edited by noobie1000; June 25th, 2013 at 05:31 AM.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by noobie1000
    From what I understand, system 2 is obtained if system 1 is rotated +90 degrees along the x-axis, in which case, you will get co-ordinates of system2 if you multiply co-ordinates 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 co-ordinates in system2.
    Many thanks, I'll try that now and come back.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    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
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    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.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    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 axis-angle combination.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    40
    Rep Power
    11
    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 y-axis (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.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    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 re-check 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.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    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 re-check 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.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    40
    Rep Power
    11
    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.
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0
    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!
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo