Skip to content

Waypoints: Add functions for piecewise linear interpolation #804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JPonte opened this issue Jan 8, 2025 · 2 comments
Closed

Waypoints: Add functions for piecewise linear interpolation #804

JPonte opened this issue Jan 8, 2025 · 2 comments
Assignees

Comments

@JPonte
Copy link
Contributor

JPonte commented Jan 8, 2025

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:

case class PiecewiseLerpResult(value: Vector2, derivative: Vector2)

// at should be a value between 0.0 and 1.0
def piecewiseLerp(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 period
def piecewiseLerp(vectors: Vector2, over: Seconds): SignalFunction[Seconds, PiecewiseLerpResult]

// From 0.0 to 1.0
def piecewiseLerp(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.

@davesmith00000 davesmith00000 changed the title Add functions for piecewise linear interpolation Waypoints: Add functions for piecewise linear interpolation Jan 9, 2025
@davesmith00000
Copy link
Member

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.

@davesmith00000
Copy link
Member

Work completed by @JPonte, will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants