RhinoCommon Python Rotation to Euler YawPitchRoll

Hi everyone,

Im having some problems with the Transform.GetYawPitchRoll Method. I made a Rotationmatrix that is Rotating a Circle by a given Vector Using Transform.Rotation. Actually the geometrical Rotation is done properly but if i want to calculate the Euler-Angles using the Transform.GetYawPitchRoll Method it fails to calculate the Angles. I cant understand why.
What am i doing wrong ? Am i missing something ?
I`m using Rhino6 Version 6.16.19190.7001

Here`s my method…

import System.Guid, System.Array, System.Enum
import rhinoscriptsyntax as rs
import scriptcontext as sc
import os, re, sys, fileinput, math, time, copy
from shutil import copyfile
from Rhino import *
from Rhino.Geometry import*
from System.Drawing import *

def positionhandler():
    zvec = Vector3d(0,0,1)
    centerpoint = Point3d(-480.65,1389.284,301.983)
    rotvek = Vector3d(-0.001547,0.030698,0.999528)
    rotvek.Unitize()
    circleorig = Circle(centerpoint,42.61).ToNurbsCurve()
    circlerot = circleorig.Duplicate()
    rot = Transform.Rotation(zvec,rotvek,centerpoint)
    eulerypr = Transform.GetYawPitchRoll(rot)
    if eulerypr[0] == True:
        print("Euler YPR")
        print(eulerypr)
    else:
        print("No Eulerypr")
    circlerot.Transform(rot)
    sc.doc.Objects.AddCurve(circleorig)
    sc.doc.Objects.AddCurve(circlerot)

Hi Patrick

Not directly answering but saying Hi and sharing how to effectively post your python code:

If you format it like so:

```python
import rhinoscriptsyntax as rs

def doprint_foobar():
    print foobar

doprint_foobar()
```

you get neatly formatted code:

import rhinoscriptsyntax as rs

def doprint_foobar():
    print foobar

doprint_foobar()

If you want you can edit your post to better format it (maybe be not for novice users)

I think this is the formatted code for testing:

import System.Guid, System.Array, System.Enum
import rhinoscriptsyntax as rs
import scriptcontext as sc
import os, re, sys, fileinput, math, time, copy
from shutil import copyfile
from Rhino import *
from Rhino.Geometry import*
from System.Drawing import *

def positionhandler():
    zvec = Vector3d(0,0,1)
    centerpoint = Point3d(-480.65,1389.284,301.983)
    rotvek = Vector3d(-0.001547,0.030698,0.999528)
    rotvek.Unitize()
    circleorig = Circle(centerpoint,42.61).ToNurbsCurve()
    circlerot = circleorig.Duplicate()
    rot = Transform.Rotation(zvec,rotvek,centerpoint)
    eulerypr = Transform.GetYawPitchRoll(rot)
    if eulerypr[0] == True:
        print('Euler YPR')
        print(eulerypr)
    else:
        print('No Eulerypr')
    circlerot.Transform(rot)
    sc.doc.Objects.AddCurve(circleorig)
    sc.doc.Objects.AddCurve(circlerot)
    
    
positionhandler()

-Willem

1 Like

Hello Willem,

thanks for the hint.

In order for this to work you need to perform the rotation at the origin point:

def positionhandler():
    zvec = Vector3d(0,0,1)
    #centerpoint = Point3d(-480.65,1389.284,301.983)
    centerpoint = Point3d.Origin
    rotvek = Vector3d(-0.001547,0.030698,0.999528)
    ...

you may then after translate to the desired position

Hey David,

it worked ! Thank you Very Much !

Greetz

Patrick