0

so my problem is that to code a curve i need at minimum 3 points, a start and end point and a third (or more) for the line to curve out and not be straight anymore. i need to make random start and end points so finding the curve point has proven difficult as soon as different angles are considered as the curve does not bend smoothly anymore but still points up. if there's a formula to build an equilateral triangle out of a single line that would solve my problems right there. other solutions that come to mind would be great. been trying alot of stupid ideas for a long time to get this function to work in any random position.

  • I don't have enough reputation to comment, but can't you just have random values for `a`, `b`, `c` and `d` in the equation `ax^3 + bx^2 + cx + d`? That would give you 3 points. –  Apr 18 '21 at 09:18
  • no, i do not want the other points to be random. i am essentially trying to make a formula to build an equilateral triangle with only a line – Dephenistrator Apr 18 '21 at 10:37

1 Answers1

0

If your two points are P and Q there are two choices for the other vertex R of an equileteral triangle with PQ forming one side.

You can compute these like this:

M.x = (P.x+Q.x)/2.0
M.y = (P.y+Q.y)/2.0 -- M mid point of P and Q
N.x = P.y-Q.y
N.y = Q.x-P.x -- N perpendicular to PQ, same length as PQ
s = sqrt(3.0)/2.0 -- ie sin( 60 degrees)

R.x = M.x + s*N.x
R.y = M.y + s*N.y -- one choice for R
R.x = M.x - s*N.x
R.y = M.y - s*N.y -- the other choice for R
dmuir
  • 4,211
  • 2
  • 14
  • 12
  • that looks amazing! the fact that you got two different answers for negative positive makes you the first person to understand what im asking, thank you so much! – Dephenistrator Apr 19 '21 at 05:57