C# 在另一个等边三角形的边上绘制等边三角形

C# Drawing equilateral triangles on the sides of another equilateral triangle

我一直在尝试在一个更大的三角形的边上画等边三角形。第一个三角形是通过设置点 A、B 和 C 的单独方法绘制的。到目前为止,我刚从两条边开始,我能够找到较小三角形的前两个点,但我无法确定正确的公式第三个。我尝试刷新三角函数的记忆,但我陷入了僵局。

        float a =0;

        Point p = new Point(pnlDisplay.Width / 2 - (pnlDisplay.Width / 2) /3, 200);
        Triangle t = new Triangle(p, pnlDisplay.Width / 3, 0);
        drawEqTriangle(e, t);


        Point p1 = new Point();
        Point p2 = new Point();
        Point p3 = new Point();


        p1.X = Convert.ToInt32(A.X + t.size / 3);
        p1.Y = Convert.ToInt32(A.Y);

        p2.X = Convert.ToInt32(A.X + (t.size - t.size / 3));
        p2.Y = Convert.ToInt32(A.Y);
        //////////////////////////////
        p3.X = Convert.ToInt32((A.X - t.size / 3) * Math.Sin(a));
        p3.Y = Convert.ToInt32((A.Y - t.size / 3) * Math.Cos(a));
        drawTriangle(e, p1, p2, p3);


        p1.X = Convert.ToInt32((B.X - t.size / 3 * Math.Cos(t.angle + Math.PI / 3)));
        p1.Y = Convert.ToInt32((B.Y + t.size / 3 * Math.Sin(t.angle+ Math.PI / 3)));

        p2.X = Convert.ToInt32((B.X - (t.size - t.size / 3) * Math.Cos(t.angle + Math.PI / 3)));
        p2.Y = Convert.ToInt32((B.Y + (t.size - t.size / 3) * Math.Sin(t.angle + Math.PI / 3)));
        //////////////////////////////
        p3.X = Convert.ToInt32((B.X - t.size / 3) * Math.Cos(a));
        p3.Y = Convert.ToInt32((B.Y - t.size / 3) * Math.Tan(a));
        drawTriangle(e, p1, p2, p3);

这可能是数学部分的问题,但我想我会先在这里尝试。我需要的是 p3.X 和 p3.Y

的公式

如有任何帮助,我们将不胜感激。

编辑:将 "a" 更改为浮动 a = Convert.ToSingle( 60 * Math.PI / 180);

结果如下:

最终编辑: 使用 MBo 的答案:

让我们为任何三角形方向构建通用公式(请注意,值得为大三角形使用 A[] 数组而不是明确的 A、B、C 顶点)

    p1.X = A.X * 2 / 3 + B.X / 3;
    p1.Y = A.Y * 2 / 3 + B.Y / 3;

    p2.X = A.X / 3 + B.X * 2 / 3;
    p2.Y = A.Y / 3 + B.Y * 2 / 3;

    D.X = (A.X - p1.X);
    D.Y = (A.Y - p1.Y);

    //note - angle sign depends on ABC orientation CW/CCW
    p3.X = p1.X + D.X * Cos(2*Pi/3) - D.Y * Sin(2*Pi/3)
    p3.Y = p1.Y + D.X * Sin(2*Pi/3) + D.Y * Cos(2*Pi/3)