 # Grasshopper "Align Plane" command in Rhino Common

Hi everyone,

I want to align plane in Rhino Common script like Grasshopper but couldn’t find any method for it. “Rotate” method is similar to functionality of “align plane” gh command but it requires angle and point, I want to use only plane and direction as an input.

Thanks for help
Best Regards,
Tahirhan

There is no such method because it is trivial to do it. Calculate the angle and rotate it. Or use this:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Transform_Rotation.htm

1 Like

``````private void RunScript(Plane p, Vector3d d, ref object A)
{
double s,t;
var pt = p.Origin + d;
p.ClosestParameter(pt, out s, out t);
double angle = -Math.Atan2(s, t) + Math.PI * 0.5;
p.Rotate(angle, p.ZAxis, p.Origin);
A = p;
}
``````

You can also use NodeInCode to exactly generate same result as grasshopper components:

``````private void RunScript(Plane p, Vector3d d, ref object A)
{
var ap = Rhino.NodeInCode.Components.FindComponent("AlignPlane");
if(ap == null) return;
var ap_function = (System.Func<object,object,object>) ap.Delegate;
var result = (IList<object>) ap_function(p, d);
A = result;
}
``````

AlignPlane.gh (15.6 KB)

1 Like

You can use PlaneToPlane on the Transform class:

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Transform_PlaneToPlane.htm

1 Like

Thanks a lot, I implemented the script to my code and it worked. I was trying to calculate the angle with normals and axis components but i see calculation of the angle is different in your script. Thanks!