/// Update the bounding box of the path void UpdateBounds() { if (boundsUpToDate) { return; } // Loop through all segments and keep track of the minmax points of all their bounding boxes MinMax3D minMax = new MinMax3D(); for (int i = 0; i < NumSegments; i++) { Vector3[] p = GetPointsInSegment(i); minMax.AddValue(p[0]); minMax.AddValue(p[3]); List <float> extremePointTimes = PathUtility.ExtremePointTimes(p[0], p[1], p[2], p[3]); foreach (float t in extremePointTimes) { minMax.AddValue(MathUtility.CubicBezier(p, t)); } } boundsUpToDate = true; bounds = new Bounds((minMax.Min + minMax.Max) * .5f, minMax.Max - minMax.Min); }
/// Update the bounding box of the path public Bounds CalculateBoundsWithTransform(Transform transform) { // Loop through all segments and keep track of the minmax points of all their bounding boxes MinMax3D minMax = new MinMax3D(); for (int i = 0; i < NumSegments; i++) { Vector3[] p = GetPointsInSegment(i); for (int j = 0; j < p.Length; j++) { p[j] = MathUtility.TransformPoint(p[j], transform, space); } minMax.AddValue(p[0]); minMax.AddValue(p[3]); List <float> extremePointTimes = PathUtility.ExtremePointTimes(p[0], p[1], p[2], p[3]); foreach (float t in extremePointTimes) { minMax.AddValue(MathUtility.CubicBezier(p, t)); } } return(new Bounds((minMax.Min + minMax.Max) * .5f, minMax.Max - minMax.Min)); }
public static Bounds CalculateSegmentBounds (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) { MinMax3D minMax = new MinMax3D (); minMax.AddValue (p0); minMax.AddValue (p3); List<float> extremePointTimes = ExtremePointTimes (p0,p1,p2,p3); foreach (float t in extremePointTimes) { minMax.AddValue (CubicBezierUtility.EvaluateCurve (p0, p1, p2, p3, t)); } return new Bounds ((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min); }
public static Bounds CalculateBounds(Vector3[] points) { MinMax3D minMax = new MinMax3D(); minMax.AddValue(points[0]); minMax.AddValue(points[3]); List <float> extremePointTimes = ExtremePointTimes(points[0], points[1], points[2], points[3]); foreach (float t in extremePointTimes) { minMax.AddValue(CubicBezierUtility.EvaluateCurve(points, t)); } return(new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min)); }
public static Bounds CalculateBounds(Vector3[] points) { Debug.Assert(points.Length == 4, "Incorrect number of points supplied to cubic bezier function (expected 4)"); MinMax3D minMax = new MinMax3D(); if (points.Length >= 4) { minMax.AddValue(points[0]); minMax.AddValue(points[3]); List <float> extremePointTimes = ExtremePointTimes(points[0], points[1], points[2], points[3]); foreach (float t in extremePointTimes) { minMax.AddValue(CubicBezierUtility.EvaluateCurve(points, t)); } } return(new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min)); }
public static Bounds CalculateBounds(Vector3[] points) { Debug.Assert( points.Length == 4, "Incorrect number of points supplied to cubic bezier function. Expected 4, but received " + points.Length); var minMax = new MinMax3D(); if (points.Length >= 4) { minMax.AddValue(points[0]); minMax.AddValue(points[3]); var extremePointTimes = ExtremePointTimes(points[0], points[1], points[2], points[3]); foreach (var t in extremePointTimes) { minMax.AddValue(EvaluateCurve(points, t)); } } return(new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min)); }