/// <summary> /// /// </summary> /// <returns>a Vector3 in world coordinates </returns> public static Vector3 GetWorldPosAtCurvePoint(BezierSegment seg, float dist) { //Find the total length of the curve float totalLength = SS_Common.GetLengthSimpsons(0f, 1f, seg); //Use Newton–Raphsons method to find the t value from the start of the curve //to the end of the distance we have float t = SS_Common.FindTValue(dist, totalLength, seg); //Get the coordinate on the Bezier curve at this t value Vector3 pos = SS_Common.DeCasteljausAlgorithm(t, seg); return(pos); }
//Divide the curve into equal steps public void DivideSegmentIntoSteps(BezierSegment seg) { //Find the total length of the curve float totalLength = SS_Common.GetLengthSimpsons(0f, 1f, seg); //How many sections do we want to divide the curve into int parts = numSteps; //reset the curve steps Array <======= EDIT MIO segmentSteps.Clear(); segmentSteps.Add(transform.TransformPoint(seg.A)); //What's the length of one section? float sectionLength = totalLength / (float)parts; //Init the variables we need in the loop float currentDistance = 0f + sectionLength; //The curve's start position Vector3 lastPos = seg.A; for (int i = 1; i <= parts; i++) { //Use Newton–Raphsons method to find the t value from the start of the curve //to the end of the distance we have float t = SS_Common.FindTValue(currentDistance, totalLength, seg); //Get the coordinate on the Bezier curve at this t value Vector3 pos = SS_Common.DeCasteljausAlgorithm(t, seg); //Save the last position lastPos = pos; //Add current pos to vector list <======= EDIT MIO segmentSteps.Add(transform.TransformPoint(pos)); //Add to the distance traveled on the line so far currentDistance += sectionLength; } }