Results 1 to 3 of 3

Thread: Procedurally Generating Equilateral Triangle

  1. #1
    Newbie
    Joined
    Aug 2018
    From
    Texas
    Posts
    2

    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.

    Procedurally Generating Equilateral Triangle-sides.pngProcedurally Generating Equilateral Triangle-pointers.png


    Many thanks.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    6,356
    Thanks
    2732

    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}$
    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor

    Joined
    Aug 2006
    Posts
    22,148
    Thanks
    3039
    Awards
    1

    Re: Procedurally Generating Equilateral Triangle

    Quote Originally Posted by lunabell View Post
    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.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. equilateral triangle help
    Posted in the Geometry Forum
    Replies: 3
    Last Post: Sep 1st 2011, 07:29 PM
  2. equilateral triangle
    Posted in the Trigonometry Forum
    Replies: 0
    Last Post: Nov 10th 2010, 02:07 AM
  3. ABC Equilateral Triangle
    Posted in the Algebra Forum
    Replies: 1
    Last Post: May 31st 2010, 07:22 PM
  4. Equilateral Triangle
    Posted in the Geometry Forum
    Replies: 2
    Last Post: Nov 20th 2008, 03:13 PM
  5. Equilateral Triangle
    Posted in the Geometry Forum
    Replies: 1
    Last Post: Oct 1st 2006, 02:07 PM

/mathhelpforum @mathhelpforum