# Thread: Procedurally Generating Equilateral Triangle

1. ## Procedurally Generating Equilateral Triangle

I am following a youtube series that demonstrates how to code the classic video game "Asteroids". Part of the program allows the user to generate a equilateral triangle procedurally to serve as the players ship given an angle such as 90 degrees, and the length measurement of the side.

But I am not certain how the program is able to use vectors generated from the formulas to actually draw the triangle.

It has been awhile since I have done trig, but I still remember basics of trigonometry such as the SOH CAH TOA ratios, unit circle, solving for lengths or angles of a missing side. For all the formulas noted, it would take a side measurement for example 15px, and multiply that by the vector for example cos(90), sin(90) becomes 15*cos(90), 15*sin(90).

Here are the formulas used, and an example of the program output to generate the triangle using these formulas.

Many thanks.

2. ## Re: Procedurally Generating Equilateral Triangle

I think I'd just establish the baseline 3 points in some coordinate system you're happy with and then apply a rotation matrix to each point to determine the vertices of the rotated triangle, and then use whatever drawline() routine is in your programming language to connect each of the 3 points to the other 2 to draw the triangle.

the rotation matrix which rotates a point counterclockwise by $\theta$ radians is given by

$r(\theta) = \begin{pmatrix}\cos(\theta) &-\sin(\theta) \\ \sin(\theta) &\cos(\theta)\end{pmatrix}$

3. ## Re: Procedurally Generating Equilateral Triangle

Originally Posted by lunabell
Part of the program allows the user to generate a equilateral triangle
But I am not certain how the program is able to use vectors generated from the formulas to actually draw the triangle.
There are many many different programming languages to do drawings. I don't know which you have.
However, the points $(0,0),~(r,r\sqrt3),~\&~(2r,0)$ are the vertices of an equilateral triangle with sides of length $2r$

Now I at one time programmed demonstration lessons using an academic version of MathCad. In that program I used vector methods to make all geometric figures. Perhaps if we can know more about your program then we can be more helpful.