public static void CloneParametric()
        {
            double                position   = 1;
            double                xExpected  = 5;
            double                yExpected  = 4;
            LinearCurve           curve      = new LinearCurve(new CartesianCoordinate(1, 2), new CartesianCoordinate(5, 4));
            LinearCurveParametric parametric = new LinearCurveParametric(curve);

            double xValue = parametric.Xcomponent.ValueAt(position);

            Assert.AreEqual(xExpected, xValue);

            double yValue = parametric.Ycomponent.ValueAt(position);

            Assert.AreEqual(yExpected, yValue);

            CartesianParametricEquationXY parametricClone = parametric.CloneParametric();

            double xValueClone = parametricClone.Xcomponent.ValueAt(position);

            Assert.AreEqual(xExpected, xValueClone);

            double yValueClone = parametricClone.Ycomponent.ValueAt(position);

            Assert.AreEqual(yExpected, yValueClone);
        }
예제 #2
0
        public void TestLinear()
        {
            LinearCurve d = new LinearCurve();

            float sut = d.Apply(0.1f);
            Assert.AreEqual(sut, 0.1f);
        }
        public static void GetLimitByCoordinate_Throws_ArgumentOutOfRangeException_if_Coordinate_Does_Not_Lie_On_Curve()
        {
            CartesianCoordinate     coordinate = new CartesianCoordinate(2, 2);
            ICurvePositionCartesian curve      = new LinearCurve(new CartesianCoordinate(-1, -2, Tolerance), new CartesianCoordinate(4, 3, Tolerance));

            Assert.Throws <ArgumentOutOfRangeException>(() => CurveLimit.GetLimitByCoordinate(coordinate, curve));
        }
예제 #4
0
        public void DeferredUpdate()
        {
            lock (this)
            {
                if (!_dirty)
                {
                    return;
                }
                _dirty = false;
            }

            FromMatrix = MatrixD.CreateWorld(From.Position, CorrectTangent(From.Tangent), From.Up);
            ToMatrix   = MatrixD.CreateWorld(To.Position, CorrectTangent(To.Tangent), To.Up);


            var ext = Math.Max((FromMatrix.Translation - ToMatrix.Translation).Length() / 3, 1f);
            var d1  = default(Vector3D);
            var d2  = default(Vector3D);

            if (Mode != CurveMode.Linear)
            {
                if (_ctl0.HasValue)
                {
                    d1 = Vector3D.Transform(_ctl0.Value, FromMatrix);
                }
                else
                {
                    d1 = FromMatrix.Translation + (FromMatrix.Forward * ext);
                }
                if (_ctl1.HasValue)
                {
                    d2 = Vector3D.Transform(_ctl1.Value, ToMatrix);
                }
                else
                {
                    d2 = ToMatrix.Translation - (ToMatrix.Forward * ext);
                }
            }


            switch (Mode)
            {
            case CurveMode.Linear:
                Curve = new LinearCurve(From.Position, To.Position);
                break;

            case CurveMode.QuadraticBez:
                Curve = new QuadraticCurve(FromMatrix.Translation, (d1 + d2) / 2, ToMatrix.Translation);
                break;

            case CurveMode.CubicBez:
                Curve = new CubicCurve(FromMatrix.Translation, d1, d2, ToMatrix.Translation);
                break;

            default:
                throw new Exception($"Unsupported curve mode {Mode}");
            }

            CurveUpdated?.Invoke(this);
        }
        [TestCase(3, 2, 4, 3, 5, 3, 3, 5, 2, 3, 0, 0, 1, -1, -2, -3, -3, -4, -3, -5, -5, -3, -3, -2)] // Mirror about 45 deg sloped line to quadrant III, reversed line
        public static void MirrorAboutLine(
            double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5,
            double lineX1, double lineY1, double lineX2, double lineY2,
            double x1Result, double y1Result, double x2Result, double y2Result, double x3Result, double y3Result, double x4Result, double y4Result, double x5Result, double y5Result)
        {
            IEnumerable <CartesianCoordinate> coordinates = new List <CartesianCoordinate>()
            {
                new CartesianCoordinate(x1, y1),
                new CartesianCoordinate(x2, y2),
                new CartesianCoordinate(x3, y3),
                new CartesianCoordinate(x4, y4),
                new CartesianCoordinate(x5, y5),
            };
            Polygon shape = new Polygon(coordinates);

            IEnumerable <CartesianCoordinate> coordinatesResult = new List <CartesianCoordinate>()
            {
                new CartesianCoordinate(x1Result, y1Result),
                new CartesianCoordinate(x2Result, y2Result),
                new CartesianCoordinate(x3Result, y3Result),
                new CartesianCoordinate(x4Result, y4Result),
                new CartesianCoordinate(x5Result, y5Result),
            };
            Polygon shapeResult = new Polygon(coordinatesResult);

            LinearCurve referenceLine = new LinearCurve(new CartesianCoordinate(lineX1, lineY1), new CartesianCoordinate(lineX2, lineY2));

            Polygon newShape = shape.MirrorAboutLine(referenceLine) as Polygon;

            Assert.AreEqual(shapeResult.PointAt(0), newShape.PointAt(0));
            Assert.AreEqual(shapeResult.PointAt(1), newShape.PointAt(1));
            Assert.AreEqual(shapeResult.PointAt(2), newShape.PointAt(2));
            Assert.AreEqual(shapeResult.PointAt(3), newShape.PointAt(3));
            Assert.AreEqual(shapeResult.PointAt(4), newShape.PointAt(4));
        }
예제 #6
0
        public void TestLinear()
        {
            LinearCurve d = new LinearCurve();

            float sut = d.Apply(0.1f);

            Assert.AreEqual(sut, 0.1f);
        }
        /// <summary>
        /// Mirrors the specified segment about the Y-axis through point J.
        /// </summary>
        /// <returns>IPathSegment.</returns>
        public virtual IPathSegment MirrorAboutAxisJY()
        {
            LinearCurve referenceLine = new LinearCurve(J, new CartesianCoordinate(J.X, J.Y + 1));

            return(new LineSegment(
                       CartesianCoordinate.MirrorAboutLine(I, referenceLine),
                       CartesianCoordinate.MirrorAboutLine(J, referenceLine)));
        }
예제 #8
0
        public static void InintializeCurve()
        {
            Curve curve = new LinearCurve(new CartesianCoordinate(-1, -2, Tolerance), new CartesianCoordinate(4, 3, Tolerance));

            curve.Tolerance = Tolerance;
            RangeWithLimits = new CurveRange(curve);
            RangeWithLimits.Start.SetLimitByX(-0.5);
            RangeWithLimits.End.SetLimitByX(2);
        }
예제 #9
0
        /// <summary>
        /// Mirrors the specified coordinate about the specified line.
        /// </summary>
        /// <param name="coordinate">The coordinate.</param>
        /// <param name="referenceLine">The reference line.</param>
        /// <returns>CartesianCoordinate.</returns>
        public static CartesianCoordinate MirrorAboutLine(
            CartesianCoordinate coordinate,
            LinearCurve referenceLine)
        {
            CartesianCoordinate reflectionLinePoint = referenceLine.CoordinateOfPerpendicularProjection(coordinate);
            CartesianOffset     deltaReflection     = 2 * reflectionLinePoint.OffsetFrom(coordinate);

            return(coordinate + deltaReflection);
        }
        public static void GetLimitByCoordinate()
        {
            CartesianCoordinate     expectedLimit = new CartesianCoordinate(2, 1, Tolerance);
            ICurvePositionCartesian curve         = new LinearCurve(new CartesianCoordinate(-1, -2, Tolerance), new CartesianCoordinate(4, 3, Tolerance));

            CartesianCoordinate limit = CurveLimit.GetLimitByCoordinate(expectedLimit, curve);

            Assert.AreEqual(expectedLimit, limit);
        }
예제 #11
0
        public static void Initialization()
        {
            Curve curve = new LinearCurve(new CartesianCoordinate(-1, -2, Tolerance), new CartesianCoordinate(4, 3, Tolerance));

            curve.Tolerance = Tolerance;
            CurveRange range = new CurveRange(curve);

            Assert.AreEqual(CartesianCoordinate.Origin(), range.Start.Limit);
            Assert.AreEqual(CartesianCoordinate.Origin(), range.End.Limit);
        }
        public static void Initialization()
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(1, 2), new CartesianCoordinate(3, 4));
            LinearCurve curve2 = new LinearCurve(new CartesianCoordinate(-1, 2), new CartesianCoordinate(-3, 4));

            IntersectionLinearLinear intersections = new IntersectionLinearLinear(curve1, curve2);

            Assert.AreEqual(curve1, intersections.Curve1);
            Assert.AreEqual(curve2, intersections.Curve2);
        }
예제 #13
0
        /// <summary>
        /// Mirrors the specified shape about the specified reference line.
        /// </summary>
        /// <param name="referenceLine">The reference line.</param>
        /// <returns>IList&lt;IPathSegment&gt;.</returns>
        protected SegmentsBoundary mirrorAboutLine(LinearCurve referenceLine)
        {
            IList <IPathSegment> segments = new List <IPathSegment>();

            foreach (IPathSegment segment in _polyline)
            {
                segments.Add(segment.MirrorAboutLine(referenceLine));
            }
            return(new SegmentsBoundary(segments));
        }
        public static void CloneLimit()
        {
            Curve      curve      = new LinearCurve(new CartesianCoordinate(-1, -2, Tolerance), new CartesianCoordinate(4, 3, Tolerance));
            CurveLimit curveLimit = new CurveLimit(curve);

            curveLimit.SetLimitByX(2);

            CurveLimit curveLimitClone = curveLimit.CloneLimit();

            Assert.AreEqual(curveLimit.Limit, curveLimitClone.Limit);
        }
예제 #15
0
        /// <summary>
        /// The y-coordinate of the intersection of the vertically projected line with the provided segment.
        /// </summary>
        /// <param name="xPtN">The x-coordinate of pt n, where the projection starts.</param>
        /// <param name="ptI">Vertex i of the segment.</param>
        /// <param name="ptJ">Vertex j of the segment.</param>
        /// <returns>System.Double.</returns>
        public static double IntersectionPointY(
            double xPtN,
            CartesianCoordinate ptI,
            CartesianCoordinate ptJ)
        {
            if (LinearCurve.IsVertical(ptI, ptJ))
            {
                throw new ArgumentException("Segment is vertical, so intersection point is either infinity or NAN.");
            }

            LinearCurve curve = new LinearCurve(ptI, ptJ);

            return(curve.Y(xPtN));
        }
        [TestCase(1, 1, 4, 3, 9, 5, 12, 7)] // Sloped-Sloped Parallel
        public static void IntersectionCoordinates_Static_of_Collinear_Lines_Returns_Empty_Array(
            double x1, double y1, double x2, double y2,
            double x3, double y3, double x4, double y4)
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            curve1.Tolerance = Tolerance;
            LinearCurve curve2 = new LinearCurve(new CartesianCoordinate(x3, y3), new CartesianCoordinate(x4, y4));

            curve2.Tolerance = Tolerance;

            CartesianCoordinate[] intersectionCoordinates = IntersectionLinearLinear.IntersectionCoordinates(curve1, curve2);
            Assert.AreEqual(0, intersectionCoordinates.Length);
        }
예제 #17
0
        [TestCase(5, 16, 15, 6, 5, 6, 6)]  // No Intersection in translated coordinates
        public static void IntersectionCoordinates_Static_of_Not_Intersecting_Returns_Empty_Array(
            double x1, double y1, double x2, double y2,
            double x, double y, double r)
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            curve1.Tolerance = Tolerance;
            CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y));

            curve2.Tolerance = Tolerance;

            CartesianCoordinate[] intersectionCoordinates = IntersectionLinearCircular.IntersectionCoordinates(curve1, curve2);

            Assert.AreEqual(0, intersectionCoordinates.Length);
        }
예제 #18
0
            /// <summary>
            /// Initializes a new instance of the <see cref="IntersectionProperties"/> class.
            /// </summary>
            /// <param name="linearCurve">The linear curve.</param>
            /// <param name="circularCurve">The circular curve.</param>
            public IntersectionProperties(LinearCurve linearCurve, CircularCurve circularCurve)
            {
                Tolerance       = Generics.GetTolerance(linearCurve, circularCurve);
                Transformations = new Transformations(circularCurve.LocalOrigin, new CartesianCoordinate(circularCurve.LocalOrigin.X + 1, circularCurve.LocalOrigin.Y));
                LinearCurve linearCurveLocal = transformToLocal(linearCurve);

                D = Numbers.ValueAsZeroIfWithinAbsoluteTolerance(linearCurveLocal.ControlPointI.CrossProduct(linearCurveLocal.ControlPointJ), Tolerance);
                CartesianOffset offset = linearCurveLocal.Range.End.Limit.OffsetFrom(linearCurveLocal.Range.Start.Limit);

                dx = offset.X();
                dy = offset.Y();
                dr = AlgebraLibrary.SRSS(dx, dy);

                IncidenceDelta = Numbers.ValueAsZeroIfWithinAbsoluteTolerance((circularCurve.Radius * dr).Squared() - D.Squared(), Tolerance);
            }
        [TestCase(1, 1, 4, 3, 9, 6, 12, 9, true)]  // Sloped-Sloped
        public static void AreIntersecting_Static(
            double x1, double y1, double x2, double y2,
            double x3, double y3, double x4, double y4,
            bool expectedResult)
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            curve1.Tolerance = Tolerance;
            LinearCurve curve2 = new LinearCurve(new CartesianCoordinate(x3, y3), new CartesianCoordinate(x4, y4));

            curve2.Tolerance = Tolerance;

            bool result = IntersectionLinearLinear.AreIntersecting(curve1, curve2);

            Assert.AreEqual(expectedResult, result);
        }
예제 #20
0
    private void Awake()
    {
        //récupération des composants
        rend = GetComponent <UILineRenderer>();
        rect = GetComponent <RectTransform>();

        //création de la courbe
        //List<Vector2> keyLst = new List<Vector2> { new Vector2(0, 0), new Vector2(1, 1) };
        List <Vector2> keyLst = new List <Vector2> {
            new Vector2(0, 0), new Vector2(0.5f, 1), new Vector2(1, 0.75f)
        };

        CurrentCurve = new LinearCurve(keyLst);

        OnValidate();
    }
예제 #21
0
        [TestCase(5, 13, 12, 6, 5, 6, 6, true)]  // Sloped Intersection in translated coordinates
        public static void AreIntersecting_Static(
            double x1, double y1, double x2, double y2,
            double x, double y, double r,
            bool expectedResult)
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            curve1.Tolerance = Tolerance;
            CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y));

            curve2.Tolerance = Tolerance;

            bool result = IntersectionLinearCircular.AreIntersecting(curve1, curve2);

            Assert.AreEqual(expectedResult, result);
        }
        [TestCase(1, 1, 4, 3, 9, 6, 12, 9, 10, 7)]       // Sloped-Sloped
        public static void IntersectionCoordinates_Static(
            double x1, double y1, double x2, double y2,
            double x3, double y3, double x4, double y4,
            double xExpected, double yExpected)
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            curve1.Tolerance = Tolerance;
            LinearCurve curve2 = new LinearCurve(new CartesianCoordinate(x3, y3), new CartesianCoordinate(x4, y4));

            curve2.Tolerance = Tolerance;

            CartesianCoordinate[] intersectionCoordinates = IntersectionLinearLinear.IntersectionCoordinates(curve1, curve2);

            Assert.AreEqual(xExpected, intersectionCoordinates[0].X, Tolerance);
            Assert.AreEqual(yExpected, intersectionCoordinates[0].Y, Tolerance);
        }
예제 #23
0
        private static void LoadTrack(int version, Track track, BinaryReader stream)
        {
            var e = (AnimationChannelDataTrack)track;

            int type           = stream.ReadByte();
            int keyframesCount = stream.ReadInt32();
            var propertyType   = type == 1 ? typeof(Quaternion) : typeof(Float3);

            e.Title          = type == 0 ? "Position" : (type == 1 ? "Rotation" : "Scale");
            e._type          = type;
            e.MemberTypeName = propertyType.FullName;
            e.ValueSize      = type == 1 ? Quaternion.SizeInBytes : Float3.SizeInBytes;

            var keyframes = new object[keyframesCount];

            for (int i = 0; i < keyframesCount; i++)
            {
                var    time = stream.ReadSingle();
                object value;
                if (type == 1)
                {
                    value = stream.ReadQuaternion();
                }
                else
                {
                    value = stream.ReadFloat3();
                }
                keyframes[i] = new LinearCurve <object> .Keyframe
                {
                    Time  = time,
                    Value = value,
                };
            }

            if (e.Curve != null && e.Curve.ValueType != propertyType)
            {
                e.Curve.Dispose();
                e.Curve = null;
            }
            if (e.Curve == null)
            {
                e.CreateCurve(propertyType, typeof(LinearCurveEditor <>));
            }
            e.Curve.SetKeyframes(keyframes);
        }
예제 #24
0
        [TestCase(5, 14.4852813742386, 13.4852813742386, 6, 5, 6, 6, 9.24264068711928, 10.2426406871193)]     // Sloped Tangent in Quadrant 1 in translated coordinates
        public static void IntersectionCoordinates_Static_of_Tangents_Returns_Tangent_Coordinate(
            double x1, double y1, double x2, double y2,
            double x, double y, double r,
            double x1Expected, double y1Expected)
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            curve1.Tolerance = Tolerance;
            CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y));

            curve2.Tolerance = Tolerance;

            CartesianCoordinate[] intersectionCoordinates = IntersectionLinearCircular.IntersectionCoordinates(curve1, curve2);

            Assert.AreEqual(1, intersectionCoordinates.Length);
            Assert.AreEqual(x1Expected, intersectionCoordinates[0].X, Tolerance);
            Assert.AreEqual(y1Expected, intersectionCoordinates[0].Y, Tolerance);
        }
예제 #25
0
 private void createRegressionLineToolStripMenuItem_Click(object sender, EventArgs e)
 {
     char[] variables = SelectVariableDialog.SelectVariables("Regression line", DataSet.Variables, "Independent variable:", "Dependent variable:");
     if (variables != null && variables[0] != variables[1])
     {
         if (variables != null && SaveChanges())
         {
             LinearCurve line = DataSet.FitLinear(variables[0], variables[1]);
             Document.Add(line.ToEquation());
             MessageBox.Show(
                 "The regression line has been added to the Document.\r\n" + line.ToString(),
                 "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         MessageBox.Show("The chosen variables must not be the same.", "Statistics", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #26
0
        [TestCase(5, 13, 12, 6, 5, 6, 6, 6.102084, 11.897916, 10.897916, 7.102084)] // Sloped Intersection in translated coordinates
        public static void IntersectionCoordinates(
            double x1, double y1, double x2, double y2,
            double x, double y, double r,
            double x1Expected, double y1Expected,
            double x2Expected, double y2Expected)
        {
            LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            curve1.Tolerance = Tolerance;
            CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y));

            curve2.Tolerance = Tolerance;

            IntersectionLinearCircular intersections = new IntersectionLinearCircular(curve1, curve2);

            CartesianCoordinate[] intersectionCoordinates = intersections.IntersectionCoordinates();

            Assert.AreEqual(x1Expected, intersectionCoordinates[0].X, Tolerance);
            Assert.AreEqual(y1Expected, intersectionCoordinates[0].Y, Tolerance);
            Assert.AreEqual(x2Expected, intersectionCoordinates[1].X, Tolerance);
            Assert.AreEqual(y2Expected, intersectionCoordinates[1].Y, Tolerance);
        }
        private static IBoundaryShape MapBoundaryShape(XElement Xsegment)
        {
            var            XboundaryShapeCurve = Xsegment.Element(boundaryShapeCurveElementName);
            IBoundaryShape boundaryshape       = null;
            var            boundaryShapeType   = int.Parse(XboundaryShapeCurve.Attribute(boundaryShapeTypeAttributeName).Value);

            if (boundaryShapeType == 1)
            {
                boundaryshape = new LinearCurve(
                    new RealPoint(double.Parse(XboundaryShapeCurve.Element("P0").Attribute("x").Value.Replace(".", ",")), double.Parse(XboundaryShapeCurve.Element("P0").Attribute("y").Value.Replace(".", ","))),
                    new RealPoint(double.Parse(XboundaryShapeCurve.Element("P1").Attribute("x").Value.Replace(".", ",")), double.Parse(XboundaryShapeCurve.Element("P1").Attribute("y").Value.Replace(".", ",")))
                    );
            }
            else if (boundaryShapeType == 3)
            {
                boundaryshape = new BezieCurve(
                    new RealPoint(double.Parse(XboundaryShapeCurve.Element("P0").Attribute("x").Value.Replace(".", ",")), double.Parse(XboundaryShapeCurve.Element("P0").Attribute("y").Value.Replace(".", ","))),
                    new RealPoint(double.Parse(XboundaryShapeCurve.Element("P3").Attribute("x").Value.Replace(".", ",")), double.Parse(XboundaryShapeCurve.Element("P3").Attribute("y").Value.Replace(".", ","))),
                    new RealPoint(double.Parse(XboundaryShapeCurve.Element("P1").Attribute("x").Value.Replace(".", ",")), double.Parse(XboundaryShapeCurve.Element("P1").Attribute("y").Value.Replace(".", ","))),
                    new RealPoint(double.Parse(XboundaryShapeCurve.Element("P2").Attribute("x").Value.Replace(".", ",")), double.Parse(XboundaryShapeCurve.Element("P2").Attribute("y").Value.Replace(".", ","))));
            }
            return(boundaryshape);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="LinearParametricY" /> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 public LinearParametricY(LinearCurve parent) : base(parent)
 {
 }
예제 #29
0
 /// <summary>
 /// Mirrors the specified shape about the specified reference line.
 /// </summary>
 /// <param name="referenceLine">The reference line.</param>
 /// <returns>IPathSegment.</returns>
 public Shape MirrorAboutLine(LinearCurve referenceLine)
 {
     _polyline = new PolyLine(mirrorAboutLine(referenceLine));
     return(this);
 }
 public static void SetUp()
 {
     curve      = new LinearCurve(new CartesianCoordinate(1, 2), new CartesianCoordinate(5, 4));
     parametric = new LinearCurveParametric(curve);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LinearCurveParametric" /> class.
 /// </summary>
 /// <param name="parent">The parent object whose properties are used in the associated parametric equations.</param>
 public LinearCurveParametric(LinearCurve parent)
 {
     _x = new LinearParametricX(parent);
     _y = new LinearParametricY(parent);
 }