如何使用WPF实现一个平面三角形3D运动效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

实现效果如下:

思路:封装三角形三个顶点和路径的三角形类,图形渲染时同步更新公共顶点三角形的顶点位置。
步骤:
1、三角形类Triangle.cs
public Point A, B, C;//初始三个顶点
public Point VA, VB, VC;//运动的三个顶点
public Path trianglePath;//三角形路径
public Color triangleColor;//填充
public double ColorIndex;//颜色深度
public Triangle(Point a, Point b, Point c, Color co, double z)
{
A = VA = a;
B = VB = b;
C = VC = c;
triangleColor = co;
ColorIndex = z;
trianglePath = new Path();
Draw();
}
///
/// 绘制三角形
///
public void Draw()
{
var g = new StreamGeometry();
using (StreamGeometryContext context = g.Open())
{
context.BeginFigure(VA, true, true);
context.LineTo(VB, true, false);
context.LineTo(VC, true, false);
}
trianglePath.Data = g;
trianglePath.Fill = new SolidColorBrush(triangleColor);
}