Parameterise a line represented by n points

53 Views Asked by At

I'm trying to write a program where I draw points at constant increments, regardless of how curvy a road is. For example, a straight line of length 10 and increment 2 would have 5 points spaced 2 meters away from each other, and would be as simple as adding 2 to the value of the previous point. However it gets a lot more complex when dealing with lines that aren't straight.

Let's say I have n points which represent a line. Is it possible to parameterise it in say, Cartesian coordinates, so that I can find any point on that line simply by passing in an independent variable? For example, say I have a line made up of n points, all connected by line segments. Is there a way I can find a point on any of those lines through a parameterised vector? For example, a circle with equation x^2+y^2 = 4 can be parameterised as r(theta) = (2cos(theta) , 2sin(theta). Is there a way to do something similar with the image below, with the first point n = 0 being used as the reference point. Line made up of n points

1

There are 1 best solutions below

7
On

Yes, we can parameterize that but the greater the number of segments the uglier the parameterization becomes because of the cases in the definition.

For a line segment between two points $p, q$ we parametrize the segment by $$f(t)=(1-t)p + tq$$ where $t\in [0,1]$.

If we want to add another point $r$ to get two line segments: one between $p$ and $q$ and another between $q$ and $r$ we have to do something like $$f(t) = \begin{cases} (1-t)p + tq, & 0\le t\le 1 \\ (2-t)q + (t-1)r & 1\lt t\le 2 \end{cases}$$

We continue in this manner until we include $n$ different cases for the $n$ different segments.

This parameterization is not unique. Nothing says we have to travel along each segment in the same amount of time. We can also rescale the domain so the entire parameterization happens in an interval other than size $n$.

Update If you are writing a computer program and have many points then we don't need a parameterization as above. We can reuse the parameterization of one segment along with a look up table to navigate along the curve.

Store the individual segments as pairs of points in a 0-indexed array. The first segment will be segment $0$ and the $n$th segment will be $n-1$.

At time $t$, $0\le t\lt n$, use the integer part to find the segment and plug the remainder into the formula for a single line segment above. Use the points in the array for $p$ and $q$ in the formula.