I have been trying to draw equilateral triangles on the sides of a larger triangle. The first triangle is drawn by a separate method setting points A, B and C. So far I have just started with two sides, I am able to find the first two points of the smaller triangles, but I am unable to determine the correct formula for the third. I have tried refreshing my memory of trigonometry but I am at an impasse.
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);
This may be a question for the math subsection, but I thought I would try here first. What I need is the formula for p3.X and p3.Y
Any help would be greatly appreciated.
EDIT: changing "a" to float a = Convert.ToSingle( 60 * Math.PI / 180);
results in this:
FINAL EDIT: Using MBo's answer:
Let's build universal formulas for any triangle orientation (note that it is worth to use A[] array for big triangle instead of explicit A,B,C vertices)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With