You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The existing interpolation functions are between two values of Double, Vector2 or Point, but for some cases it's useful to interpolate between a larger group of values, which apparently is called piecewise linear interpolation. Non linear versions exist but this one should be fairly simple to implement.
A generic signature would look something like this:
caseclassPiecewiseLerpResult(value: Vector2, derivative: Vector2)
// at should be a value between 0.0 and 1.0defpiecewiseLerp(vectors: List[Vector2], at: Double):PiecewiseLerpResult
The two values it returns are the interpolated value and it's derivative which for a use case where the Vector2 represents position, the value would be the current position and the derivative its direction and speed.
And to integrate with Indigo's signals it would look like this:
// Over a time perioddefpiecewiseLerp(vectors: Vector2, over: Seconds):SignalFunction[Seconds, PiecewiseLerpResult]
// From 0.0 to 1.0defpiecewiseLerp(vectors: Vector2):SignalFunction[Double, PiecewiseLerpResult]
I created a type for the result because I find tuples like (Vector2, Vector2) can get confusing.
An assumption of this function is that the waypoints would be spaced relative to their distance, rather than equaly distributed over time. This would maintain constant traveling speed over the whole path which is something we usually want. But if we would also create a picewiseLerp for Double values instead of Vector2, it's not clear that this would be the desired behaviour.
The text was updated successfully, but these errors were encountered:
davesmith00000
changed the title
Add functions for piecewise linear interpolation
Waypoints: Add functions for piecewise linear interpolation
Jan 9, 2025
For context: The discussion here was about navigating characters / NPCs around a game level, and the fact that we don't have a nice way to define a path of waypoints that a character will follow.
The above description is quite correct, but additionally I think it would be nice to model this as a WayPoint type somehow, so that we can (perhaps later as a second step) do things like emit events when waypoints are reached and have different types of connecting paths and so on.
The existing interpolation functions are between two values of
Double
,Vector2
orPoint
, but for some cases it's useful to interpolate between a larger group of values, which apparently is called piecewise linear interpolation. Non linear versions exist but this one should be fairly simple to implement.A generic signature would look something like this:
The two values it returns are the interpolated value and it's derivative which for a use case where the Vector2 represents position, the value would be the current position and the derivative its direction and speed.
And to integrate with Indigo's signals it would look like this:
I created a type for the result because I find tuples like
(Vector2, Vector2)
can get confusing.An assumption of this function is that the waypoints would be spaced relative to their distance, rather than equaly distributed over time. This would maintain constant traveling speed over the whole path which is something we usually want. But if we would also create a picewiseLerp for Double values instead of Vector2, it's not clear that this would be the desired behaviour.
The text was updated successfully, but these errors were encountered: