保存三角形以重绘 C#



我想将矩形绘制到列表中所需的所有点保存,以便能够绘制另一个三角形并保留前一个三角形。我在其他形状(如矩形等(上通过将它们保存在

List< Rectangle > _rect = new List< Rectangle >

并使用

foreach(Rects rect in _rect)

当涉及到三角形时该怎么办?

public PointF[] tPoints { get; set; }
public void DrawTriangle(PaintEventArgs e)
{
tPoints = new PointF[3];
float angle = 0;
tPoints[0].X = x;
tPoints[0].Y = y;
tPoints[1].X = (float)(x + width * Math.Cos(angle));
tPoints[1].Y = (float)(y + width * Math.Sin(angle));
tPoints[2].X = (float)(x + width * Math.Cos(angle - Math.PI / 3));
tPoints[2].Y = (float)(y + width * Math.Sin(angle - Math.PI / 3));
e.Graphics.InterpolationMode = InterpolationMode.High;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawPolygon(new Pen(color, strokeThickness), tPoints);
}

您可以自己创建这样的数据类型!

struct Triangle {
// all your need for a triangle is three points, isn't it?
public Point PointA { get; }
public Point PointB { get; }
public Point PointC { get; }
public Triangle(Point a, Point b, Point c) {
PointA = a;
PointB = b;
PointC = c;
}
}

然后,您可以创建它的列表:

var triangles = new List<Triangles>();

相关内容

  • 没有找到相关文章

最新更新