0

I'm trying to make a properly-rotated isosceles triangle. I have the following data:

  • The (x, y) coordinates of the vertex point, A
  • The (x, y) coordinates of the midpoint of the base, am
  • The width of the base, a

And I need to find the coordinates of the other two points, B and C. What is an algorithm for finding these last two points with only the above information? Searching Google just got me a lot of equations that assume it's pointed directly up, but I need these to be placed before a transformation is performed.

An isosceles triangle rotated so that the vertex (labeled with a blue capital A) is in the lower-left and the base (labeled with a red lower-case a) is on the upper-right. The base is bisected by its midpoint (labeled by a green a with a subscript m). The other two points are labeled with a purple capital B and an orange capital C, respectively.

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • 2
    I'm voting to close this question as off-topic because it is about maths. – High Performance Mark Jul 25 '16 at 16:15
  • @HighPerformanceMark Please let me know where the line lies between having trouble computing numbers in pseudocode and having trouble doing maths, so I know where to put future questions. Also, how my question differs from the other 25k [`math`](http://stackoverflow.com/questions/tagged/math) questions. – Ky - Jul 26 '16 at 14:59

1 Answers1

1

To find B and C:

  1. find the normalized direction vector a_mA = (A - a_m)/|A - a_m|
  2. find a vector orthogonal to the vector a_mA – let's call it a_mA'
    • a_mA' = (-a_mA.y, a_mA.x)
  3. to find B, step width/2 units in the direction of a_mA' and add a_m:
    • B = (width/2)*a_mA' + a_m
  4. to find C, step -width/2 units in the direction of a_mA' and add a_m:
    • C = (-width/2)*a_mA' + a_m

JsFiddle example: https://jsfiddle.net/asq7h2jd/

sarasvati
  • 792
  • 12
  • 30
  • Why the downvote? The answer provides a concrete algorithm with an example implementation. – sarasvati Jul 25 '16 at 17:18
  • Beautiful, works like a charm! No idea why the downvote, but my up counteracted it :) – Ky - Jul 25 '16 at 18:19
  • @BenLeggiero Thank you :) I'm glad I could help. If you like the answer please consider accepting it. – sarasvati Jul 25 '16 at 18:30
  • 1
    Done and done. Just one thing: I adapted your JS code for my implementation, but I think your answer here uses `a_mA` where it should use `a_mA'` in one or two places, as trying to implement this didn't wield the results I expected. – Ky - Jul 25 '16 at 18:37
  • @BenLeggiero yes, you're perfectly right – thanks, I've edited the answer (the error was in the computation of `B` and `C`). – sarasvati Jul 25 '16 at 18:41