Math help for creating random curved lines

273 Views Asked by At

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.

1

There are 1 best solutions below

1
On

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