这很容易做到。您必须确保您的区域 vertese 已排序,否则您可能会遇到一些问题,但它是一个简单的参数。如果形状不是空心的,这里是一个例子:
// the verteses has to be in order and direction doesn't matter here
// i simply assume it's drawn on X/Y for the purpose of the example
public static Region CreateRegion(List<Point3D> verteses)
{
// create a curve list representing
var curves = new List<ICurve>();
// for each vertex we add them to the list
for (int i = 1; i < verteses.Count; i++)
{
curves.Add(new Line(verteses[i - 1], verteses[i]));
}
// close the region
curves.Add(new Line(verteses.Last(), verteses[0]));
return new Region(new CompositeCurve(curves, true), Plane.XY, true);
}
// this extrude in Z the region
public static Solid CreateSolidFromRegion(Region region, double extrudedHeight)
{
// extrude toward Z by the amount
return region.ExtrudeAsSolid(new Vector3D(0, 0, 1), extrudedHeight);
}
从 vertese 创建一个 10 x 10 x 10 的立方体的简单示例(制作立方体的方法要简单得多,但为了简单起见,我将制作一个立方体)
// create the 4 verteses
var verteses = new List<Point3D>()
{
new Point3D(0, 0, 0),
new Point3D(10, 0, 0),
new Point3D(10, 10, 0),
new Point3D(0, 10, 0)
}
// create the region on the XY plane using the static method
var region = CreateRegion(verteses);
// extrude the region in Z by 10 units
var solid = CreateSolidFromRegion(region, 10d);