目前,我有一个脚本,创建一个椭圆,我试图增加调整线条厚度的能力。因为据我所知,您不能正常使用椭圆来实现这一点,因此我试图使用PELLIPSE变量将其转换为Polyline。但是,即使使用变量设置,它似乎也没有转换结束。是否有更简单的方法来解决这一问题,或者有可能解决这个问题?
当前椭圆代码:
public override Entity getAcObj()
{
return
new Ellipse(
new Point3d(Markup.XCoord, Markup.YCoord, 0),
Vector3d.ZAxis,
new Vector3d((Markup.Locations[0].XCoord - Markup.Locations[1].XCoord) / 2, -(Markup.Locations[2].YCoord - Markup.Locations[3].YCoord) / 2, 0),
(Math.Abs(Markup.Locations[0].YCoord - Markup.Locations[3].YCoord) / 2)
/ (Math.Abs(Markup.Locations[0].XCoord - Markup.Locations[1].XCoord) / 2),
0,
360 * Math.Atan(1.0) / 45.0
)
{
Layer = Layer
};
}PELLIPSE变量设置:
Application.SetSystemVariable("PELLIPSE", 1);发布于 2021-08-05 16:13:08
PELLIPSE系统变量仅适用于本机ELLIPSE命令。您可以将它与Editor.Command()方法结合使用,但只用于封闭椭圆。或者,您可以使用GeometryExtensions库,它为Ellipse类型提供了一个ToPolyline()扩展方法。
var polyline = ellipse.ToPolyline();发布于 2021-11-23 10:06:45
在不同的背景下,我也遇到了同样的问题。这是我的代码,手动将椭圆转换为polyline:(抱歉,德语评论)最初的任务是将DWG转换为Protobuf-结构,因此代码比需要的要复杂。请忽略所有“Protobuf.”元素。我希望它还能解释算法。
Ellipse ellipse = entity as Ellipse;
// vorsichtshalber unsinnige Ellipsen ignorieren (auch wenn man diese interaktiv gar nicht erzeugen kann)
if (ellipse.StartAngle == ellipse.EndAngle) { return 0; }
// ...wir machen eine Polylinie daraus mHv.:
// Ellipse = (a x cos(alpha), b x sin(alpha)), a = Hauptachse(nvektor), b = Nebenachse(nvektor), 0 <= alpha <= 2 x PI
ProtobufLayer protolayer = this.GetOrCreateProtobufLayer(newLayer, newLayerId, 1);
ProtobufEntity protoentity = GDBProtobufHelper.DefaultEntityPolyline(false);
double angle, angleSum = 0, angleStep = Math.PI / 18;
bool stop = false;
// Punkte (auf der Ellipse) einzeln hinzufügen
angle = ellipse.StartAngle;
while (true)
{
// (alle Winkelangaben/-funktionen sind in Bogenmass)
Vector3d vector = ellipse.MajorAxis * Math.Cos(angle) + ellipse.MinorAxis * Math.Sin(angle);
protoentity.EntityPolyline.Points.Add(new ProtobufPolyPoint()
{
Bulge = 0,
Point = new ProtobufRealPoint()
{
X = ellipse.Center.X + vector.X,
Y = ellipse.Center.Y + vector.Y
}
});
if (stop) { break; }
// nächsten Winkel berechnen
angle += angleStep;
if (angle >= 2 * Math.PI) { angle -= 2 * Math.PI; }
angleSum += angleStep;
// sind wir - beim nächsten Mal, der aktuelle neue Punkt muss ja noch dazu! - fertig?
// (Fallunterscheidung, falls Start > Ende, ist es etwas komplzierter)
if ((ellipse.StartAngle < ellipse.EndAngle) && (angleSum >= ellipse.EndAngle - ellipse.StartAngle))
{
angle = ellipse.EndAngle;
stop = true;
}
if ((ellipse.StartAngle > ellipse.EndAngle) && (angleSum >= 2 * Math.PI + ellipse.EndAngle - ellipse.StartAngle))
{
angle = ellipse.EndAngle;
stop = true;
}
}https://stackoverflow.com/questions/68655990
复制相似问题