public static Lerp ( Vector3D, from, Vector3D, to, double t ) : Vector3D, | ||
from | Vector3D, | |
to | Vector3D, | |
t | double | |
return | Vector3D, |
public CurveSample Sample(double f) { if (f <= 0) { return(new CurveSample(new Vector3D(positions[0]), tangent(0))); } int N = arc_len.Length; if (f >= arc_len[N - 1]) { return(new CurveSample(new Vector3D(positions[N - 1]), tangent(N - 1))); } for (int k = 0; k < N; ++k) { if (f < arc_len[k]) { int a = k - 1; int b = k; if (arc_len[a] == arc_len[b]) { return(new CurveSample(new Vector3D(positions[a]), tangent(a))); } double t = (f - arc_len[a]) / (arc_len[b] - arc_len[a]); return(new CurveSample( Vector3D.Lerp(positions[a], positions[b], t), Vector3D.Lerp(tangent(a), tangent(b), t))); } } throw new ArgumentException("SampledArcLengthParam.Sample: somehow arc len is outside any possible range"); }
public static void Include(ref BoundingSphereD sphere, ref BoundingSphereD otherSphere) { if (sphere.Radius == double.MinValue) { sphere.Center = otherSphere.Center; sphere.Radius = otherSphere.Radius; return; } double distance = Vector3D.Distance(sphere.Center, otherSphere.Center); if (distance + otherSphere.Radius <= sphere.Radius) // Other sphere is contained in this sphere { return; } else if (distance + sphere.Radius <= otherSphere.Radius) // This sphere is contained in other sphere { sphere = otherSphere; } else { // Now we know that center will lie between the old centers. Let's calculate linterpolation factors a and b: // r_1 + a*d = r_2 + b*d and a + b = 1 give: // a = (d + r_2 - r_1) / (2*d) // b = (d + r_1 - r_2) / (2*d) = 1 - a double a = (distance + otherSphere.Radius - sphere.Radius) / (2.0f * distance); Vector3D center = Vector3D.Lerp(sphere.Center, otherSphere.Center, a); double radius = (distance + sphere.Radius + otherSphere.Radius) / 2; sphere.Center = center; sphere.Radius = radius; } }
public override void Interpolation(double interpolationHd, float interpolationLd, long timePassed) { //TODO FIXME NAsty bug here, not a number float arithmetic exception sometimes - surely a server side fix to do ! Quaternion.Slerp(ref _lookAtDirection.ValuePrev, ref _lookAtDirection.Value, interpolationLd, out _lookAtDirection.ValueInterp); Quaternion.Slerp(ref _cameraYAxisOrientation.ValuePrev, ref _cameraYAxisOrientation.Value, interpolationLd, out _cameraYAxisOrientation.ValueInterp); Vector3D.Lerp(ref _worldPosition.ValuePrev, ref _worldPosition.Value, interpolationHd, out _worldPosition.ValueInterp); }
public static void Include(ref BoundingSphereD sphere, ref BoundingSphereD otherSphere) { if (sphere.Radius == double.MinValue) { sphere.Center = otherSphere.Center; sphere.Radius = otherSphere.Radius; } else { double num = Vector3D.Distance(sphere.Center, otherSphere.Center); if ((num + otherSphere.Radius) > sphere.Radius) { if ((num + sphere.Radius) <= otherSphere.Radius) { sphere = otherSphere; } else { double amount = ((num + otherSphere.Radius) - sphere.Radius) / (2.0 * num); Vector3D vectord = Vector3D.Lerp(sphere.Center, otherSphere.Center, amount); double num3 = ((num + sphere.Radius) + otherSphere.Radius) / 2.0; sphere.Center = vectord; sphere.Radius = num3; } } } }
private void UpdatePackets() { if (!_init) { _init = true; Init(); } var toRemove = new List <PacketItem>(); foreach (PacketItem packet in _packets) { packet.Ticks++; packet.Position = Vector3D.Lerp(Origin, Target, _multiplier * packet.Ticks); //delete the packet once it gets to the destination if (_multiplier * packet.Ticks > 1) { toRemove.Add(packet); } } foreach (PacketItem removePacket in toRemove) { _packets.Remove(removePacket); } //if the last packet to go out is more than 10m from origin, add a new one PacketItem lastPacket = _packets.LastOrDefault(); if (lastPacket != null && Vector3D.DistanceSquared(lastPacket.Position, Origin) > _spacingSq) { _packets.Add(new PacketItem(Origin)); } }
/// <summary> /// Draws a cropped billboard in world space facing the +Z direction of the matrix specified. Cropping is /// performed s.t. any parts outside the box defined by maskMin and maskMax are not rendered. For /// NON-TEXTURED billboards ONLY. This method will warp textures. Units in meters, matrix transform /// notwithstanding. /// </summary> public void DrawCropped(ref CroppedBox box, ref MatrixD matrix) { box.bounds = box.bounds.Intersect(box.mask.Value); Vector2 size = box.bounds.Size, pos = box.bounds.Center; Vector3D worldPos = new Vector3D(pos.X, pos.Y, 0d); MyQuadD quad; Vector3D.TransformNoProjection(ref worldPos, ref matrix, out worldPos); MyUtils.GenerateQuad(out quad, ref worldPos, size.X * .5f, size.Y * .5f, ref matrix); if (skewRatio != 0f) { Vector3D start = quad.Point0, end = quad.Point3, offset = (end - start) * skewRatio * .5; quad.Point0 = Vector3D.Lerp(start, end, skewRatio) - offset; quad.Point3 = Vector3D.Lerp(start, end, 1d + skewRatio) - offset; quad.Point1 -= offset; quad.Point2 -= offset; } AddBillboard(ref this, ref quad); }
/// <summary> /// Интерполяция вектора к другому вектору /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <param name="amt">Value between 0.0 (old vector) and 1.0 (new vector). 0.9 is very near the new vector. 0.5 is halfway in between</param> /// <returns>Новый вектор</returns> public static Vector3D Lerp(Vector3D v1, Vector3D v2, double amt) { Vector3D tmp = new Vector3D(); tmp = v1.CopyToVector(); return(tmp.Lerp(v2, amt)); }
public List <HitInfo> IntersectTriangle(Triangle triangle) { List <HitInfo> res = new List <HitInfo>(); for (int i = 0; i < vertices.Count; i++) { LineSegment2D l1 = new LineSegment2D(V2(vertices[i]), V2(vertices[(i + 1) % vertices.Count])); for (int j = 0; j < 3; j++) { LineSegment2D l2 = new LineSegment2D(V2(triangle.Vertex(j)), V2(triangle.Vertex((j + 1) % 3))); Vector2D point; if (l1.LineIntersect(l2, out point)) { double distance = (point - V2(vertices[i])).magnitude; double segmentLength = l1.Length(); //if (l1.DoLinesIntersect(l2)){ double normalizedDistance = distance / segmentLength; Vector3D point3D = Vector3D.Lerp(new Vector3D(vertices[i]), new Vector3D(vertices[(i + 1) % vertices.Count]), normalizedDistance); res.Add(new HitInfo(i, j, point3D.ToVector3())); } /*Vector2 intersectionPoint; * if (LineLineIntersection(from,to, tFrom, tTo,out intersectionPoint)){ * float normalizedDistance = Vector3.Dot(to-from, tTo-tFrom); * Vector3 point3D = Vector3.Lerp (vertices[i], vertices[(i+1)%vertices.Count], normalizedDistance); * res.Add(new HitInfo(i,j,point3D)); * }*/ } } return(res); }
public static void UpdateFacePoint(SensorAdapter adapter, Frame frame, Vector2D facePoint, Transform facePointTransform, Transform viewPlane, Visualization visualization, float updateSmoothness) { bool ignoreAdapter = VideoPlayer.IsPlaying || !Application.isEditor && Application.platform == RuntimePlatform.Android; if ((!ignoreAdapter && adapter == null) || facePointTransform == null || viewPlane == null) { return; } Vector3 viewPlanePosition = viewPlane.position; LightBuzz.Quaternion viewPlaneRotation = viewPlane.rotation; Vector3D viewPlaneScale = viewPlane.localScale; if (viewPlane.GetType() == typeof(RectTransform)) { viewPlaneScale.Set(viewPlaneScale.X * ((RectTransform)viewPlane).root.localScale.x * ((RectTransform)viewPlane).rect.size.x, viewPlaneScale.Y * ((RectTransform)viewPlane).root.localScale.y * ((RectTransform)viewPlane).rect.size.y, 1); } float smoothness = Mathf.Lerp(1f, Time.deltaTime, updateSmoothness); Vector3D position = visualization == Visualization.Image ? facePoint : VideoPlayer.IsPlaying ? default(Vector2D) : !Application.isEditor && Application.platform == RuntimePlatform.Android ? facePoint : adapter.ImageToDepthSpace(facePoint); Vector2Int resolution = visualization == Visualization.Image ? new Vector2Int(frame.ImageWidth, frame.ImageHeight) : new Vector2Int(frame.DepthWidth, frame.DepthHeight); facePointTransform.position = Vector3D.Lerp(facePointTransform.position, position.GetPositionOnPlane(resolution.x, resolution.y, viewPlanePosition, viewPlaneRotation, viewPlaneScale), smoothness); }
/// <summary> /// Creates the smallest BoundingSphereD that can contain a specified BoundingBoxD. /// </summary> /// <param name="box">The BoundingBoxD to create the BoundingSphereD from.</param><param name="result">[OutAttribute] The created BoundingSphereD.</param> public static void CreateFromBoundingBox(ref BoundingBoxD box, out BoundingSphereD result) { Vector3D.Lerp(ref box.Min, ref box.Max, 0.5f, out result.Center); double result1; Vector3D.Distance(ref box.Min, ref box.Max, out result1); result.Radius = result1 * 0.5f; }
public static void CreateFromBoundingBox(ref BoundingBoxD box, out BoundingSphereD result) { double num; Vector3D.Lerp(ref box.Min, ref box.Max, 0.5, out result.Center); Vector3D.Distance(ref box.Min, ref box.Max, out num); result.Radius = num * 0.5; }
internal void Play() { for (int cnt = 0; cnt < 50; cnt++) { var norm = MyUtils.GetRandomVector3Normalized(); PointSpread point = new PointSpread(norm, m_center + Vector3D.Multiply(norm, MyUtils.GetRandomFloat(10, 50))); points.Add(point); } count++; if (count < 120) { foreach (var point in points) { var color = Color.LightBlue.ToVector4(); Vector3D vec = Vector3D.Lerp(point.pos, m_center, count / 120d); var cnter = Vector3D.Lerp(vec, m_center, 0.2); MySimpleObjectDraw.DrawLine(vec, cnter, MyStringId.GetOrCompute("particle_laser"), ref color, 0.1f); } if (count == 42 && CoreWarpExplode.instance.isSpecial) { cena = new MyEntity3DSoundEmitter(null); cena.SetPosition(m_center); cena.SetVelocity(Vector3.Zero); MySoundPair m_bombExpl = new MySoundPair("ArcWepLrgCENAExpl"); cena.CustomMaxDistance = (float)Math.Pow(50, 2); cena.CustomVolume = 15f; cena.PlaySingleSound(m_bombExpl, true); } } else if (count < 150) { if (count == 120) { emitter = new MyEntity3DSoundEmitter(null); emitter.SetPosition(m_center); emitter.SetVelocity(Vector3.Zero); MySoundPair m_bombExpl = new MySoundPair("ArcWepLrgWarheadExpl"); emitter.CustomMaxDistance = (float)Math.Pow(50, 2); emitter.CustomVolume = 15f; emitter.PlaySingleSound(m_bombExpl, true); } foreach (var point in points) { var color = Color.LightBlue.ToVector4(); Vector3D vec = Vector3D.Lerp(point.pos, m_center, (120 - count * 4d) / 120d); var cnter = Vector3D.Lerp(vec, m_center, 0.2); MySimpleObjectDraw.DrawLine(vec, cnter, MyStringId.GetOrCompute("particle_laser"), ref color, 0.1f); } } else { done = true; } }
public static Vector3D MethNav3p(double t, MissileTarget trg, IPosition3D missPos, double missVel, object otherStuff) { //А вот тут хитро: PROP - делит отрезок, который лежит на линии визирования НАБЛ.ПУНКТ-ЦЕЛЬ. //Одна точка лежит на цели, вторая точка является точкой пересчечения линии визирования НАБЛ.ПУНКТ-ЦЕЛЬ с нормалью к ней же(perfectPoint) //(нормаль проходит через фактическое местоположение ракеты, которое может быть расположено не на линии визирования НАБЛ.ПУНКТ -> ЦЕЛЬ) //Отрезок этот делится в соотношении PROP - (1-PROP) точкой(vel2TrgPoint), в которую целится ракета //(не полностью, просто по вектору РАКЕТА -> vel2TrgPoint направлена одна из составляущей скорости ракеты ) const double PROP = 0.3d; //координаты набл пункта (одна из тех самых трех точек "цель" "ракета" >>"НАБЛ. ПУНКТ"<<) var nablPunkt = ((otherStuff == null)?Vector3D.Zero:(Vector3D)otherStuff); //Линия визирования НАБЛ.ПУНКТ -> ЦЕЛЬ var visLine = trg.Vec3D - nablPunkt; //Пропорция в которой делит линию визирования НАБЛ.ПУНКТ -> ЦЕЛЬ точка пересчечения линии визирования НАБЛ.ПУНКТ-ЦЕЛЬ с нормалью к ней же(perfectPoint) //(нормаль проходит через фактическое местоположение ракеты, которое может быть расположено не на линии визирования НАБЛ.ПУНКТ -> ЦЕЛЬ) var perfectProportion = (visLine.Norm * (missPos.Vec3D - nablPunkt)) / visLine.GetLength(); //точка пересчечения линии визирования НАБЛ.ПУНКТ-ЦЕЛЬ с нормалью к ней же(perfectPoint) //(нормаль проходит через фактическое местоположение ракеты, которое может быть расположено не на линии визирования НАБЛ.ПУНКТ -> ЦЕЛЬ) var perfectPoint = perfectProportion * visLine; //единичный вектор, лежащий в плоскости линии визирования НАБЛ.ПУНКТ -> ЦЕЛЬ и вектором скорости цели, перпендикулярный линии визирования //и направленный по ходу вектора скорости цели, если линия виз. и скорость цели параллельны, то n1=(0,0,0); var n1 = ((visLine & trg.Vel.Vec3D) & visLine).Norm; //тангенциальная состаавляющая скорости цели, относитально НАБЛ.ПУНКТ var vTrgPerpend = n1 * (n1 * trg.Vel.Vec3D); //модуль тангенциальной составляющей скорости ракеты, относитально НАБЛ.ПУНКТ var vMisPerpend = vTrgPerpend * perfectProportion; //точка в которую целится ракета //(не полностью, просто по вектору РАКЕТА -> vel2TrgPoint направлена одна из составляущей скорости ракеты ) //делит отрезок perfectPoint -> ЦЕЛЬ в соотношении PROP - (1-PROP) var vel2TrgPoint = Vector3D.Lerp(PROP, 0d, perfectPoint, 1d, visLine); //направление одной из составляущей скорости ракеты var vel2Dir = (vel2TrgPoint - missPos.Vec3D).Norm; //далее решается задача нахождения вектора скорости ракеты, при условии, //что известна ее тангенциальная составляющая, известен модуль скорости, и известно направление его второй составляющей...... (РАКЕТА -> vel2TrgPoint) var vMisPerp2 = vMisPerpend.GetLengthSquared(); var vMis2 = missVel * missVel; if (vMisPerp2 > vMis2) { return(MethNavCleanChase(t, trg, missPos, missVel, otherStuff)); } var b = vel2Dir * vMisPerpend; var b2 = b * b; var dscr = 4 * b + 4 * (vMis2 - vMisPerp2); var s1 = 0.5 * (-b + Sqrt(dscr)); //ОТВЕТ var res = vMisPerpend + s1 * vel2Dir; if (Abs(res.GetLength() - missVel) < 1E-15) { throw new Exception("Чет не работает алгоритм по корректировке по 3 точкам("); } return(res); }
public static BoundingSphereD CreateFromBoundingBox(BoundingBoxD box) { BoundingSphereD ed; double num; Vector3D.Lerp(ref box.Min, ref box.Max, 0.5, out ed.Center); Vector3D.Distance(ref box.Min, ref box.Max, out num); ed.Radius = num * 0.5; return(ed); }
public void Lerp() { var u = new Vector3D(10, 20, 30); var v = new Vector3D(30, 20, 10); Assert.AreEqual(Vector3D.Zero, Vector3D.Zero.Lerp(Vector3D.One, 0)); Assert.AreEqual(Vector3D.Zero, Vector3D.One.Lerp(Vector3D.Zero, 1)); Assert.AreEqual(new Vector3D(0.5f, 0.5f, 0.5f), Vector3D.Zero.Lerp(Vector3D.One, 0.5f)); Assert.AreEqual(new Vector3D(16, 20, 24), u.Lerp(v, 0.3f)); }
public static MatrixD BSpline(MatrixD a, MatrixD b, float t) { var up = Vector3D.Lerp(a.Up, b.Up, t); var bez = new CubicCurve(a, b); var x = bez.Sample(t); var fwd = bez.SampleDerivative(t); return(MatrixD.CreateWorld(x, Vector3D.Normalize(fwd), Vector3D.Normalize(up))); }
//Called once before the drawing sequence ==> Computed interpolated values here ! public override void VTSUpdate(double interpolationHd, float interpolationLd, float elapsedTime) { //Do interpolation on the value received at update time Vector3D.Lerp(ref _worldPosition.ValuePrev, ref _worldPosition.Value, interpolationHd, out _worldPosition.ValueInterp); Quaternion.Slerp(ref _cameraOrientation.ValuePrev, ref _cameraOrientation.Value, interpolationLd, out _cameraOrientation.ValueInterp); Quaternion.Slerp(ref _cameraYAxisOrientation.ValuePrev, ref _cameraYAxisOrientation.Value, interpolationLd, out _cameraYAxisOrientation.ValueInterp); ComputeCameraMatrices(); _frustum = new SimpleBoundingFrustum(ref _viewProjection3D); }
public void Vector3LerpTest5() { Vector3D a = new Vector3D(45.67f, 90.0f, 0f); Vector3D b = new Vector3D(double.PositiveInfinity, double.NegativeInfinity, 0); double t = 0.408f; Vector3D actual = Vector3D.Lerp(a, b, t); Assert.True(double.IsPositiveInfinity(actual.X), "Vector3D.Lerp did not return the expected value."); Assert.True(double.IsNegativeInfinity(actual.Y), "Vector3D.Lerp did not return the expected value."); }
public void Vector3LerpTest4() { Vector3D a = new Vector3D(0.0f, 0.0f, 0.0f); Vector3D b = new Vector3D(4.0f, 5.0f, 6.0f); double t = -2.0f; Vector3D expected = new Vector3D(-8.0f, -10.0f, -12.0f); Vector3D actual = Vector3D.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), "Vector3D.Lerp did not return the expected value."); }
public void Vector3LerpTest6() { Vector3D a = new Vector3D(1.68f, 2.34f, 5.43f); Vector3D b = a; double t = 0.18f; Vector3D expected = new Vector3D(1.68f, 2.34f, 5.43f); Vector3D actual = Vector3D.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), "Vector3D.Lerp did not return the expected value."); }
public MySnapshot Lerp(MySnapshot value2, float factor) { return(new MySnapshot() { Active = this.Active || value2.Active, Position = Vector3D.Lerp(this.Position, value2.Position, factor), Rotation = Quaternion.Slerp(this.Rotation, value2.Rotation, factor), LinearVelocity = Vector3.Lerp(this.LinearVelocity, value2.LinearVelocity, factor), AngularVelocity = Vector3.Lerp(this.AngularVelocity, value2.AngularVelocity, factor) }); }
public void Vector3LerpTest6() { Vector3D <float> a = new Vector3D <float>(1.68f, 2.34f, 5.43f); Vector3D <float> b = a; float t = 0.18f; Vector3D <float> expected = new Vector3D <float>(1.68f, 2.34f, 5.43f); Vector3D <float> actual = Vector3D.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Lerp did not return the expected value."); }
public void Vector3LerpTest5() { Vector3D <float> a = new Vector3D <float>(45.67f, 90.0f, 0f); Vector3D <float> b = new Vector3D <float>(float.PositiveInfinity, float.NegativeInfinity, 0); float t = 0.408f; Vector3D <float> actual = Vector3D.Lerp(a, b, t); Assert.True(float.IsPositiveInfinity(actual.X), "Vector3D<float>f.Lerp did not return the expected value."); Assert.True(float.IsNegativeInfinity(actual.Y), "Vector3D<float>f.Lerp did not return the expected value."); }
public void Vector3LerpTest4() { Vector3D <float> a = new Vector3D <float>(0.0f, 0.0f, 0.0f); Vector3D <float> b = new Vector3D <float>(4.0f, 5.0f, 6.0f); float t = -2.0f; Vector3D <float> expected = new Vector3D <float>(-8.0f, -10.0f, -12.0f); Vector3D <float> actual = Vector3D.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Lerp did not return the expected value."); }
/// <summary> /// Creates the smallest BoundingSphereD that can contain a specified BoundingBoxD. /// </summary> /// <param name="box">The BoundingBoxD to create the BoundingSphereD from.</param> public static BoundingSphereD CreateFromBoundingBox(BoundingBoxD box) { BoundingSphereD BoundingSphereD; Vector3D.Lerp(ref box.Min, ref box.Max, 0.5f, out BoundingSphereD.Center); double result; Vector3D.Distance(ref box.Min, ref box.Max, out result); BoundingSphereD.Radius = result * 0.5f; return(BoundingSphereD); }
public void Vector3LerpTest8() { Vector3D a = new Vector3D(-100); Vector3D b = new Vector3D(0.33333334f); double t = 1f; Vector3D expected = new Vector3D(0.33333334f); Vector3D actual = Vector3D.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), "Vector3D.Lerp did not return the expected value."); }
/// <summary> /// Constructs a <see cref="SlimMath.BoundingSphere"/> from a given box. /// </summary> /// <param name="box">The box that will designate the extents of the sphere.</param> /// <param name="result">When the method completes, the newly constructed bounding sphere.</param> public static void FromBox(ref BoundingBox box, out BoundingSphere result) { Vector3D.Lerp(ref box.Minimum, ref box.Maximum, 0.5f, out result.Center); double x = box.Minimum.x - box.Maximum.x; double y = box.Minimum.y - box.Maximum.y; double z = box.Minimum.z - box.Maximum.z; double distance = (double)(Math.Sqrt((x * x) + (y * y) + (z * z))); result.Radius = distance * 0.5f; }
public void Vector3LerpTest8() { Vector3D <float> a = new Vector3D <float>(-100); Vector3D <float> b = new Vector3D <float>(0.33333334f); float t = 1f; Vector3D <float> expected = new Vector3D <float>(0.33333334f); Vector3D <float> actual = Vector3D.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Lerp did not return the expected value."); }
public void Vector3LerpTest7() { Vector3D <float> a = new Vector3D <float>(0.44728136f); Vector3D <float> b = new Vector3D <float>(0.46345946f); float t = 0.26402435f; Vector3D <float> expected = new Vector3D <float>(0.45155275f); Vector3D <float> actual = Vector3D.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Lerp did not return the expected value."); }
// will return null if no edges need to be split! public List <Vector3D> SplitResample(ISampledCurve3d curve, double fMaxEdgeLen) { double fMaxSqr = fMaxEdgeLen * fMaxEdgeLen; int N = curve.VertexCount; int Nstop = (curve.Closed) ? N + 1 : N; if (lengths == null || lengths.Length < Nstop) { lengths = new double[Nstop]; } bool bFoundSplit = false; for (int i = 0; i < Nstop; ++i) { lengths[i] = curve.GetVertex(i).DistanceSquared(curve.GetVertex((i + 1) % N)); if (lengths[i] > fMaxSqr) { bFoundSplit = true; } } if (!bFoundSplit) { return(null); } List <Vector3D> vNew = new List <Vector3D>(); Vector3D prev = curve.GetVertex(0); vNew.Add(prev); for (int i = 0; i < Nstop - 1; ++i) { Vector3D next = curve.GetVertex((i + 1) % N); if (lengths[i] > fMaxSqr) { double fLen = Math.Sqrt(lengths[i]); int nSteps = (int)(fLen / fMaxEdgeLen) + 1; for (int k = 1; k < nSteps; ++k) { double t = (double)k / (double)nSteps; Vector3D mid = Vector3D.Lerp(prev, next, t); vNew.Add(mid); } } vNew.Add(next); prev = next; } return(vNew); }
public void Lerp() { var u = new Vector3D(10, 20, 30); var v = new Vector3D(30, 20, 10); Assert.AreEqual(Vector3D.Zero, Vector3D.Zero.Lerp(Vector3D.One, 0)); Assert.AreEqual(Vector3D.Zero, Vector3D.One.Lerp(Vector3D.Zero, 1)); Assert.AreEqual(new Vector3D(0.5f, 0.5f, 0.5f), Vector3D.Zero.Lerp(Vector3D.One, 0.5f)); Assert.AreEqual(new Vector3D(16, 20, 24), u.Lerp(v, 0.3f)); }