# Transform.GetYawPitchRoll Method

So i’m a little bit confused about how to get RPY from a rotation matrix. So far, I have made a rotation matrix but can get RPY because Rhino says the matrix is not a rotation matrix.
OK, I have some points on a material (surface) and want to reach those points with a Kuka robot. Robot needs coordinates and rotations to reach the target points. I have calculated 3 vectors of each points(normal, tangent and cross product of them) and made the rotation matrix. I don’t know if its the right way to calculate rotation matrix or not…any help will be appreciated!!

``````                        var rotationmatrix = new Transform(0);
rotationmatrix.M00 = tangent.X;
rotationmatrix.M01 = cross.X;
rotationmatrix.M02 = normal.X;
rotationmatrix.M03 = 0;

rotationmatrix.M10 = tangent.Y;
rotationmatrix.M11 = cross.Y;
rotationmatrix.M12 = normal.Y;
rotationmatrix.M13 = 0;

rotationmatrix.M20 = vector.Z;
rotationmatrix.M21 = cross.Z;
rotationmatrix.M22 = tangent.Z;
rotationmatrix.M23 = 0;
rotationmatrix.Affineize();

rotationmatrix.GetYawPitchRoll(out double Y, out double P, out double R);
``````

Can you provide some sample code for us to review and run?

– Dale

Thanks for the reply @dale ,
I got it anyway how to do it… but still strange why rhino doesnt accept matrix as a rotation matrix when I create it manually…
here is the code of how to get a proper rotation matrix which is created by rhino:

``````//code here
Plane planezero = new Plane();
planezero.Origin = Point3d.Origin;
planezero.XAxis = Vector3d.XAxis;
planezero.YAxis = Vector3d.YAxis;
planezero.ZAxis = Vector3d.ZAxis;

Plane manualplane = new Plane(point, vector, cross);
manualplane.ZAxis = normal;

Transform matrix = Transform.ChangeBasis(planemanual, planezero);
matrix.DecomposeRigid(out Vector3d translate, out Transform rotation, 0.1);
rotation.GetYawPitchRoll(out double Y, out double P, out double R);
``````

To transform something form one coordinate system to another, create a transform object using Transform.ChangeBasis .

If you had a point in 3-D point from world x-y coordinates and you wanted to report to the user what that point was in construction plane coordinates (of the active viewport), you would use a change of basis transformation.

If you wanted to orient an object oriented from one plane to another plane, you would not use a change of basis transformation. Rather, you use a plane-to-plane rotation transformation using Transform.PlaneToPlane . This is because you are not looking to convert from one coordinate system to another. You are simply looking orient in the same coordinate system.

Hope this helps.

– Dale

Thanks for the reply @dale , I didn’t notice that.
I’ve encountered another problem and the problem is I’m getting -infinity as RPY for some points. but have no idea why I’m getting this… (attached pics)
I’ve tried with Grasshopper and used a component to get RPY. Component is not giving infinity and gives correct values.
BTW, I’ve tried Quaternion with rhinocommon and that’s OK in that points as well.
So, I’ve 2 questions:
How GetYawPitchRoll method is calculating matrix which gives for some points infinity? or any tips that I can get correct values?
and,
Can we have a quaternion to euler method in rhinocommon?

Have you tried using the information available on the web?

– Dale

Yeah, I have used that in my code in order to convert quaternion to euler angles and It’s working OK…but it would be nice if Rhino add/implement this method as well.
and do you have any idea why GetYawPitchRoll method is giving infinity as output for some points?

Not off hand. How can I repeat this?

– Dale

@dale , I’ve sent you a pm with file. Thank you

Did you check the return value of the function. It returns false if the transform is not a rotation.

1 Like

Yep, I’ve checked. Sometimes the transform is not rigid and is not rotation as well, but it returns RPY. Dale checked that for me and I found out that I have to use surface.closestpoint to get proper normal and not brep.closestpoint .