-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Smoothness and derivatives for (cubic) curves #14306
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alice-i-cecile
added
C-Feature
A new feature, making something new possible
A-Math
Fundamental domain-agnostic mathematical operations
M-Needs-Release-Note
Work that should be called out in the blog due to impact
X-Contentious
There are nontrivial implications that should be thought through
S-Waiting-on-Author
The author needs to make changes or address concerns before this can be merged
D-Complex
Quite challenging from either a design or technical perspective. Ask for help!
labels
Jul 14, 2024
This was referenced Jul 16, 2024
mweatherley
changed the title
Smoothness for (cubic) curves / cubic spline integration
Smoothness and derivatives for (cubic) curves
Sep 27, 2024
Closing in favor of #16503 for now, which makes much less sweeping changes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Math
Fundamental domain-agnostic mathematical operations
C-Feature
A new feature, making something new possible
D-Complex
Quite challenging from either a design or technical perspective. Ask for help!
M-Needs-Release-Note
Work that should be called out in the blog due to impact
S-Waiting-on-Author
The author needs to make changes or address concerns before this can be merged
X-Contentious
There are nontrivial implications that should be thought through
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is another prototype as part of the Curve project. Once again, I have ignored NURBS for the time being.
Objective
Provide a general framework for expressing smoothness for curves (up to C2) and integrate it with
bevy_math
's existing cubic spline constructions.Solution
Continuous/differentiable curves
There are a few layers here. At the most basic level, we have a trait-enshrined way of expressing tangent spaces at the level of types:
The point of this is that it is used to define types
WithDerivative<T>
andWithTwoDerivatives<T>
that pair a point with derivatives at that point (elements of the tangent space). For example:Now, the central idea connecting this to curves is that a differentiable curve is a curve that returns
WithDerivative<T>
when sampled, so that thepoint
component provides the position andderivative
provides the velocity. We have introduced some new traits that work this way: they are just marker traits on top ofCurve<...>
:Of course, with these traits, it's worth keeping in mind that they will not be preserved by the abstract
Curve
interface methods. For example, applyingCurve::map
to a differentiable curve, the result need not generally be differentiable. The same is true for many operations, including simple ones likecompose
(which joins two curves end-to-end).On the other hand, the result of calling such functions may actually be continuous, differentiable, and so on. To bridge this gap in expressivity, we have also introduced a wrapper struct
Blessed
and a methodbless
that produces it so that the user can explicitly elevate to the level of these marker traits when necessary:Cubic segments and curves
The interoperation of cubic curves with this new technology comes in a few parts. Firstly,
CubicCurve
has an additional marker type parameterS: Smoothness
which indicates the global guarantees of smoothness that issue from the curve's construction. This parameter has four levels:Nothing
,C0
,C1
, andC2
.CubicCurve<P, S>
is itself aCurve<P>
, sampling from its position. If itsSmoothness
parameter is at leastC0
, then it is aContinuousCurve
.CubicSegment<P>
is similar, but it is always aContinuousCurve
(it has noSmoothness
parameter).To access higher derivative information through the
Curve
interface, there are a pair of new methods on bothCubicSegment
andCubicCurve
:CubicCurve
is similar. The wrapper typesSegmentDerivative
andSegmentTwoDerivatives
(truly inspired nomenclature) implementDifferentiableCurve
andTwiceDifferentiableCurve
respectively. Similarly, the wrapper types forCubicCurve
—CurveDerivative
andCurveTwoDerivatives
— implementDifferentiableCurve
andTwiceDifferentiableCurve
if the underlyingSmoothness
parameter is at leastC1
orC2
respectively.Putting it together
For starters, we can use the Curve interface pretty seamlessly in conjunction with cubic splines:
For something more complex, let's imagine we have some geometric operation which wants a differentiable curve as input and produces some output:
For a cubic curve, we could do something like this:
On the other hand, if I specified my inputs with
CubicBezier
but I made sure it's differentiable using the folds of my brain (or am willing to accept the consequences of doing something weird), I can use thebless
interface to work with it:Migration Guide
Some existing uses of the
CubicCurve
type will need to be annotated with aSmoothness
parameter in order for the program to compile. This is becauseCubicCurve
now tracks its global continuity and differentiability guarantees. For similar reasons, existing uses ofCubicCurve::push_segment
orExtend::extend
will require first callingCubicCurve::without_smoothness
in order to destroy the smoothness guarantees from the curve's construction, since arbitrary concatenations of curve segments cannot be known by the compiler to maintain these guarantees.