I was trying to create triangle inside triangle which looks like this and I dont know how to do that properly with usage of recursion. Please give me some advice, I am hopeless Triangle picture
Asked
Active
Viewed 124 times
0
-
1Looks similar to a Sierpinski Triangle. That would be a good place to start. – hijinxbassist Mar 25 '21 at 21:03
-
1That is called the [medial triangle](https://en.wikipedia.org/wiki/Medial_triangle). At each step, you replace the vertices `a, b, c` with `(b+c)/2, (c+a)/2, (a+b)/2`. – dxiv Mar 25 '21 at 21:06
-
I already did Sierpinski triangle, but this is more difficult, i dont know how to do that triangles in the middle :) – Jaroslav Milan Mar 25 '21 at 21:07
1 Answers
0
You should find a mid-point for every 3 points of the triangle using this:
midPoint1x = (x1+x2)/2 , midPoint1y = (y1+y2)/2
midPoint2x = (x1+x3)/2 , midPoint2y = (y1+y3)/2
midPoint3x = (x3+x2)/2 , midPoint3y = (y3+y2)/2
Then you should create a triangle with these 3 mid-points.
Now, you can call it recursively with new mid-points.

Positive Navid
- 2,481
- 2
- 27
- 41

Amir Motamedi
- 1
- 2