PlaneFitFromPoints Origin

import rhinoscriptsyntax as rs

section = rs.GetObjects()

guids = [rs.CurvePoints(crv, segment_index=-1) for crv in section]

pt1 = guids [0] [0]
pt2 = guids [0] [1]
pt3 = guids [0] [2]

print guids [0] [0]
print guids [0] [1]
print guids [0] [2]

points = [pt1, pt2, pt3]

rs.AddPoints(points)

plane = rs.PlaneFitFromPoints(points)
print plane
print plane [0]
print plane [1]

if plane:
    rs.AddPlaneSurface( plane, 50, 50)

I’m trying to do a script which will take some section curves, fit a plane through them, and then remap the objects from that plane to a cplane of choice.

When I PlaneFitfromPoints, and add the plane surface, the origin of the resulting plane seems to be random.

See on the left the points that were used for the PlaneFit.

My alternative idea is maybe to do something with selecting the grips and then rs.Command PlaneThroughPt from Rhino.

Well, in Rhino (scripting) a plane (not a plane surface) is infinite. So the plane may be a “best-fit” plane from your points, but where the origin is isn’t guaranteed… AddPlaneSurface assumes the origin is the origin of the plane, and makes the surface in the plane’s + X and +Y directions from there.

You can see where the origin is perhaps by putting a point at plane.Origin.

If you want the plane surface to cover the points (more or less), you could get the bounding box of the points in the plane orientation, get the lower corner of the bb and pull it to the plane, then move the plane to that point as the origin, then make your plane surface…

Something like:

import rhinoscriptsyntax as rs

section = rs.GetObjects()

guids = [rs.CurvePoints(crv, segment_index=-1) for crv in section]

pt1 = guids [0] [0]
pt2 = guids [0] [1]
pt3 = guids [0] [2]

print guids [0] [0]
print guids [0] [1]
print guids [0] [2]

points = [pt1, pt2, pt3]

rs.AddPoints(points)

plane = rs.PlaneFitFromPoints(points)

#add this
if plane:
    bb=rs.BoundingBox(points,plane)
    xform=rs.XformPlanarProjection(plane)
    new_orig=rs.PointTransform(bb[0],xform)
    x=bb[0].DistanceTo(bb[1])
    y=bb[1].DistanceTo(bb[2])
    plane.Origin=new_orig
    rs.AddPlaneSurface( plane, x, y)