/// <summary> /// Evaluates Frenet frame on the spline using curve distance from the start. Valid length is [0..TotalLength]. /// Caller must ensure that spline is valid before calling this method! /// </summary> public void EvalFrameParametrized(float length, out CurveFrame frame) { int i; float t; GetSegmentIndexAndTime(_parametrization.GetApproximateTimeParameter(length), out i, out t); ItemData segment = _data[i]; frame.Position = segment.EvalPosition(t); Vector3 velocity = segment.EvalFirstDerivative(t); Vector3 acceleration = segment.EvalSecondDerivative(t); float VDotV = velocity.Dot(velocity); float VDotA = velocity.Dot(acceleration); frame.Normal = VDotV * acceleration - VDotA * velocity; frame.Normal.Normalize(); frame.Tangent = velocity; frame.Tangent.Normalize(); frame.Binormal = frame.Tangent.Cross(frame.Normal); }
/// <summary> /// Evaluates torsion on the spline using curve distance from the start. Valid length is [0..TotalLength]. /// Caller must ensure that spline is valid before calling this method! /// </summary> public float EvalTorsionParametrized(float length) { int i; float t; GetSegmentIndexAndTime(_parametrization.GetApproximateTimeParameter(length), out i, out t); ItemData segment = _data[i]; Vector3 velocity = segment.EvalFirstDerivative(t); Vector3 acceleration = segment.EvalSecondDerivative(t); Vector3 cross = velocity.Cross(acceleration); float denom = cross.sqrMagnitude; if (denom >= Mathfex.ZeroTolerance) { Vector3 jerk = segment.EvalThirdDerivative(t); float numer = cross.Dot(jerk); return(numer / denom); } return(0f); }
/// <summary> /// Evaluates curvature on the spline using curve distance from the start. Valid length is [0..TotalLength]. /// Caller must ensure that spline is valid before calling this method! /// </summary> public float EvalCurvatureParametrized(float length) { int i; float t; GetSegmentIndexAndTime(_parametrization.GetApproximateTimeParameter(length), out i, out t); ItemData segment = _data[i]; Vector3 velocity = segment.EvalFirstDerivative(t); float speedSqr = velocity.sqrMagnitude; if (speedSqr >= Mathfex.ZeroTolerance) { Vector3 acceleration = segment.EvalSecondDerivative(t); Vector3 cross = velocity.Cross(acceleration); float numer = cross.magnitude; float denom = Mathf.Pow(speedSqr, 1.5f); return(numer / denom); } return(0f); }