Dear Jeremy, I have written several methods for projecting points on a plane and visualizing the calculated geometry, for a better understanding of what is happening
A method of projecting a point onto a plane defined by two points p1 and p2
public static XYZ PointAtPlane(XYZ point, XYZ start, XYZ end)
{
// Find the vector "v" between the start and end points:
XYZ v = end - start;
// Find the unit vector "n" of the normal to the plane passing through the given start and end points:
XYZ n = v.Normalize();
// Find the vector "u" from the center of the plane start to a given point point:
XYZ u = point - start;
// Find the distance "d" from the center of the plane to the projection of the point point on the plane:
double d = u.DotProduct(n);
// Find the projection p of a given point point on a plane:
XYZ result = point - d * n;
return result;
}
This method creates a square in the plane of the facade "In front"
//This method creates a square in the plane of the facade "In front"
public static List<XYZ> CreateRect(double hight, double wight)
{
return new List<XYZ>
{
new XYZ(-wight / 2, 0, hight / 2), // leftUp
new XYZ(wight / 2, 0, hight / 2), // rightUp
new XYZ(wight / 2, 0, -hight / 2), // rightDown
new XYZ(-wight / 2, 0, -hight / 2) // leftDown
};
}
Next, using the Create Model Line method (described below), we draw lines in the model that visualize all the vectors of the points used.
public static List<XYZ> CreateVisual(XYZ p1, XYZ p2, List<XYZ> listPoint)
{
Element red = Main.Doc.GetElement(new ElementId(490985));
Element orange = Main.Doc.GetElement(new ElementId(421355));
Element green = Main.Doc.GetElement(new ElementId(78));
CreateModelLine(Main.Doc, p1, p2, red);
List<XYZ> lPtAtPl = new List<XYZ>();
foreach (XYZ point in listPoint)
{
CreateModelLine(Main.Doc, XYZ.Zero, point, orange);
XYZ p = PointAtPlane(point, p1, p2);
CreateModelLine(Main.Doc, XYZ.Zero, p, green);
lPtAtPl.Add(p);
}
}
The "red" line style is used to display the line that defines the normal of the plane on which the point vectors of the previously created rectangle should be projected. The orange line style displays the point vectors of the original rectangle. The blue lines represent just the projection vectors of the points of the original rectangle on the plane specified by points p1 and p2
Demonstration of the projection of the rectangle createRect(10, 10) and the plane defined by the points new XYZ(0,0,0) and new XYZ(1, 2, 2)
The ModelCurve creation method is described below
public static ModelCurve CreateModelLine(Document Doc, XYZ start, XYZ end, Element lineStyle)
{
ModelCurve modelLine = null;
try
{
Line geomLine = Line.CreateBound(start, end);
XYZ lineDirection = end - start;
XYZ normal = lineDirection.CrossProduct(XYZ.BasisZ).Normalize();
if (normal.IsZeroLength())
{
normal = lineDirection.CrossProduct(XYZ.BasisY).Normalize();
if (normal.IsZeroLength())
{
normal = lineDirection.CrossProduct(XYZ.BasisX).Normalize();
}
}
Plane plane = Plane.CreateByNormalAndOrigin(normal, start);
Plane geomPlane = Plane.CreateByNormalAndOrigin(plane.Normal, start);
SketchPlane sketch = SketchPlane.Create(Doc, geomPlane);
modelLine = Doc.Create.NewModelCurve(geomLine, sketch);
modelLine.LineStyle = lineStyle;
}
catch { }
return modelLine;
}