Interface PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
- Type Parameters:
P- should be the subclassing type itselfR- should be a wildcard-generic type for a sub-interface ofPointN, such asPoint3<?>
- All Superinterfaces:
com.github.tommyettinger.crux.PointN<P>, com.github.tommyettinger.crux.PointNFloat<P,R>
- All Known Implementing Classes:
Point2Float, Point3Float, Point4Float, Point5Float, Point6Float
public interface PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
extends com.github.tommyettinger.crux.PointNFloat<P,R>
Groups functionality common to points with float components, in any dimension.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanfloatget(int index) Gets the component at the specified index.default Pinterpolate(R target, float alpha, com.github.tommyettinger.digital.Interpolations.Interpolator interpolation) Callslerp(PointN, float)with the alpha determined by the giveninterpolation.default PointNFloat<P, R> inverse()Assigns to each component of this point1fdivided by its original value.Linear-interpolates from this point toward target, moving a distance proportional to alpha and changing this point in-place if possible.setAt(int index, float value) Sets the component at the specified index to the specified value.setToRandomDirection(Random random) Sets this PointNFloat to a randomly chosen unit vector.static <P extends PointNFloat<P,?>>
PslerpGeometric(P start, P end, float alpha, P output) A geometric "slerp" (spherical linear interpolation) from the input n-dimensional float pointstartto the pointendwith the same type, moving a fraction of the distance equal toalpha, and placing the result inoutput(modifying it in-place).Methods inherited from interface com.github.tommyettinger.crux.PointN
add, cpy, div, divide, dst, dst2, isUnit, isUnit, isZero, isZero, len, len2, minus, mutable, nor, plus, rank, scl, set, setZero, sub, times
-
Method Details
-
floatingPoint
default boolean floatingPoint()- Specified by:
floatingPointin interfacecom.github.tommyettinger.crux.PointN<P extends PointNFloat<P,R>> - Specified by:
floatingPointin interfacecom.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
-
inverse
Assigns to each component of this point1fdivided by its original value. If a component is 0.0f, its value after this will be positive infinity. If a component is -0.0f, its value after this will be negative infinity. If a component is NaN, its value after this will be NaN.- Specified by:
inversein interfacecom.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>> - Returns:
- 1f divided by this point, assigned in-place to this
-
get
float get(int index) Gets the component at the specified index. Kotlin-compatible using square-bracket indexing.- Specified by:
getin interfacecom.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>> - Parameters:
index- which component to get, in order- Returns:
- the component
-
setAt
Sets the component at the specified index to the specified value.- Specified by:
setAtin interfacecom.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>> - Parameters:
index- which component to set, in ordervalue- the value to assign at index- Returns:
- this, for chaining
-
setToRandomDirection
Sets this PointNFloat to a randomly chosen unit vector. The exact algorithm is expected to vary between dimensions. In 2D, for instance, it is sufficient to get a random float between 0 and 1, and callTrigTools.cosTurns(float)andTrigTools.sinTurns(float)to get x and y. In higher dimensions, this gets more complex. A solution that works for any dimension, but is only the best option for 4D and up, is to assign to each component a normal-distributed float usingDistributor.probitF(float)with random inputs, then normalize the PointNFloat withPointN.nor().- Parameters:
random- any Random or subclass thereof- Returns:
- this point after modifications, if possible, or a new PointNFloat if this is immutable
-
lerp
Linear-interpolates from this point toward target, moving a distance proportional to alpha and changing this point in-place if possible. If this point is notPointN.mutable(), this will return a new or pooled point. The alpha is expected to be in the 0 to 1 range, inclusive.- Specified by:
lerpin interfacecom.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>> - Parameters:
target- any point with the same dimension to move towardalpha- between 0 and 1, inclusive- Returns:
- this point after modifications, if possible, or a new PointNFloat if this is immutable
-
interpolate
default P interpolate(R target, float alpha, com.github.tommyettinger.digital.Interpolations.Interpolator interpolation) Callslerp(PointN, float)with the alpha determined by the giveninterpolation. Simply returnslerp(target, interpolation.apply(alpha)).- Parameters:
target- any point with the same dimension to move towardalpha- between 0 and 1, inclusiveinterpolation- an Interpolator from digital, such asInterpolations.smooth- Returns:
- this point after modifications, if possible, or a new PointNFloat if this is immutable
-
slerpGeometric
A geometric "slerp" (spherical linear interpolation) from the input n-dimensional float pointstartto the pointendwith the same type, moving a fraction of the distance equal toalpha, and placing the result inoutput(modifying it in-place). Unlike most slerp() implementations, this works for any PointNFloat type, including 2D points on a unit circle and 4D, 5D, etc. points on hyperspheres. This does not allocate. This has undefined behavior if start and end are polar opposites; that is, points where for any coordinateain start, that coordinate in end is-aor any positive linear scale of the point where that is true. This degenerates to a linear interpolation if either start or end is the origin, and simply returns the start if both are the origin. Otherwise, this can smoothly move points that aren't already on the unit sphere towards the distance of the other point from the origin.
Based on the non-approximation code from an article by Volodymyr Agafonkin. Note that this is the "geometric slerp" rather than the version using quaternions in 3D (or rotors in other dimensions). It has been augmented slightly to handle start and end vectors that don't have unit length. This is very similar toRotationTools.slerp(int, float[], int, float[], int, float, float[], int).- Parameters:
start- an n-dimensional float point to rotate from; will not be modifiedend- another n-dimensional float point to rotate to; will not be modifiedalpha- between 0 and 1, inclusive; how much to travel from start towards endoutput- will be modified in-place so this is set to the result- Returns:
- output, after modifications.
-