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.
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[0];
}
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!