I have a non-straight line defined by a series of x, y coordinate points. I could draw a straight line on-screen directly between these points with no problem. Unfortunately, I have to draw the line in segments of equal length.
Here is an example of how I need to break up a non-straight line with 3 points into an array of several equidistant points. (ignore the final red dot, it is the result when a line does not divide evenly and is also the terminus)
Please notice the red line at the "joint". Consider that I have a line A->B->C with the vectors AB and BC forming some angle. Basically, the line bends at point B.
Segmenting a line between point A and B is no problem up to a point. But when AB does not divide evenly by the segment length, I need to do something special. I need to take that remaining length and consider it as one side of a triangle. The constant segment length is another side of a triangle that connects with the BC segment (the red line above). I need to know the length from point B to this intersection. With this information, I can continue calculating line segments on BC.
Here is the triangle I am trying to solve (hereafter I will refer to the variables as they appear on this picture) So far I have broken down the problem to using the law of cosines. c2 = a2 + b2 - 2ab * Cos(y)
The problem is that I already know c, it is the segment length. I need to solve for a (I can calculate y).
I've gotten as far as writing a polynomial equation, but now I am stuck: a2 + b2 - 2ab * Cos(y) - c2 = 0
or Ax2 + Bx + C (A = 1, B = -2b * Cos(y), C = b2 - c2, x = a)
Is this even the right approach? What do I do next? I need to implement this in Actionscript.
EDIT: Duh, I would have to use the quadratic formula. So I now get:
a = b * Cos(y) +/- SqrRoot(c2 - b2 * Sin(y)2)
Now how to put this into code...