Let's say we have two points in 2D space: A (center of blue square) and B (center of orange square). We are also given several fixed-sized lines as well as an infinite line (like a ray) with a minimal length. Furthermore we have a start-angle alpha for A.
Now how can we consecutively arrange the fixed-length lines starting at A and then the infinite line so that the angle of the first line is alpha and the infinite line exactly crosses B? Additionally there is one restriction:
- The angles between two lines should be the same (this means many constellations of values make a solution impossible, but only ones with possible solutions are to be considered)
The result can look like this (in this sample with all segments having equal length). Imagine that a line stretched from the last segment (which represents the ray at its min-length) hits B.
Now I have found a procedural solution by starting from A with 180° angles between the segments and checking whether a ray from the final segment hits B. Depending on which side of this ray, B lies, it re-starts from A with a decreased or increased angle until it overshoots the target. Then it halves the step-size and continues in the reverse direction until the next overshoot and so on. Eventually this ends when the steps have dropped below a threshold.
This image shows all the attempts of finding a semi accurate angle:
The yellow segments are the limited-length ones and the other colors are the infinite rays (where blue is the solution).
Unfortunately this quickly gets computationally heavy when high accuracy is required.
There has to be a mathematical approach\solution to this, or not?
I have realized that this arc obviously is a segment of a circle and also that the origin of that circle has to be somewhere on a line from A at angle of alpha+/-90° (so that the starting-line is a tangent of the circle and has exactly angle alpha). The problem now is, how to calculate the radius of this circle so that segments taken along points on its circumference have exactly the required length?
Hope someone has an idea. Huge thanks already!
For context if someone is interested: This is for a special type of "joint" in a physics simulation and for example to be used to make mesh-animated objects flexible and realistically bendable but NOT stretchable. Imagine a human spine for example.
That's why the segments have an enforced, fixed length and in practice, B is being forced to be at the end of the min-length of the ray-segment, however physics influence may pull it away slightly, so that it has to be corrected continuously. This solution shall yield better results than individual joints between the segments which can collapse in a zig zag in ugly ways. It already looks promising with the procedural computation solution if accuracy is high enough but it's not as performant as one expects from realtime simulations...