Example #1
0
        public void OrthonormalBasisTest()
        {
            var p = new CSP();
            p.MaxSteps = 10000000;
            var v1 = new Vector3Variable("v1", p, box);
            var v2 = new Vector3Variable("v2", p, box);
            var v3 = new Vector3Variable("v3", p, box);
            v1.Magnitude.MustEqual(1);
            v2.Magnitude.MustEqual(1);
            v3.Magnitude.MustEqual(1);
            v1.MustBePerpendicular(v2);
            v2.MustBePerpendicular(v3);
            v3.MustBePerpendicular(v1);

            for (int count = 0; count < 10; count++)
            {
                p.NewSolution();
                double magnitude = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y + v1.Z * v1.Z);
                Assert.IsTrue(MathUtil.NearlyEqual(magnitude, 1), "Magnitude not unity; was: " + magnitude);
                double dotProduct = v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z;
                Assert.IsTrue(MathUtil.NearlyEqual(dotProduct, 0), "Dot product not zero; was: " + dotProduct);

                magnitude = Math.Sqrt(v2.X * v2.X + v2.Y * v2.Y + v2.Z * v2.Z);
                Assert.IsTrue(MathUtil.NearlyEqual(magnitude, 1), "Magnitude not unity; was: " + magnitude);
                dotProduct = v2.X * v3.X + v2.Y * v3.Y + v2.Z * v3.Z;
                Assert.IsTrue(MathUtil.NearlyEqual(dotProduct, 0), "Dot product not zero; was: " + dotProduct);

                magnitude = Math.Sqrt(v3.X * v3.X + v3.Y * v3.Y + v3.Z * v3.Z);
                Assert.IsTrue(MathUtil.NearlyEqual(magnitude, 1), "Magnitude not unity; was: " + magnitude);
                dotProduct = v3.X * v1.X + v3.Y * v1.Y + v3.Z * v1.Z;
                Assert.IsTrue(MathUtil.NearlyEqual(dotProduct, 0), "Dot product not zero; was: " + dotProduct);
            }
        }
 public DotProductConstraint(FloatVariable product, Vector3Variable a, Vector3Variable b)
     : base(product.CSP)
 {
     this.product = product;
     this.a = a;
     this.b = b;
 }
        public void DotProductOneVectorFixedTest()
        {
            var p = new CSP();
            var eX = new Vector3Variable("eX", p, 1, 0, 0);
            var unknown = new Vector3Variable("unknown", p, box);
            var dot = Vector3Variable.Dot(eX, unknown);
            dot.MustEqual(0);

            for (int count = 0; count < 1000; count++)
            {
                p.NewSolution();
                Assert.IsTrue(MathUtil.NearlyEqual(unknown.X.UniqueValue, 0));
            }
        }
Example #4
0
        public void DotProductTest()
        {
            var p = new CSP();
            var v1 = new Vector3Variable("v1", p, box);
            var v2 = new Vector3Variable("v2", p, box);
            var dot = Vector3Variable.Dot(v1, v2);
            dot.MustEqual(0);

            for (int count = 0; count < 1000; count++)
            {
                p.NewSolution();
                double dotProduct = v1.X.UniqueValue * v2.X.UniqueValue + v1.Y.UniqueValue * v2.Y.UniqueValue + v1.Z.UniqueValue * v2.Z.UniqueValue;
                Assert.IsTrue(MathUtil.NearlyEqual(dotProduct, 0), "Dot product not zero; was: "+dotProduct);
            }
        }
        public void DotProductTest()
        {
            var p = new CSP();
            var v1 = new Vector3Variable("v1", p, box);
            var v2 = new Vector3Variable("v2", p, box);
            var dot = Vector3Variable.Dot(v1, v2);
            dot.MustEqual(0);

            for (int count = 0; count < 1000; count++)
            {
                try {
                    p.NewSolution ();
                }
                catch (Exception e) {
                    Console.Write ("Finding a new solution failed due to: ");
                    Console.WriteLine (e);
                    Assert.Fail ();
                }

                double dotProduct = v1.X.UniqueValue * v2.X.UniqueValue + v1.Y.UniqueValue * v2.Y.UniqueValue + v1.Z.UniqueValue * v2.Z.UniqueValue;
                Assert.IsTrue(MathUtil.NearlyEqual(dotProduct, 0), "Dot product not zero; was: "+dotProduct);
            }
        }
Example #6
0
 private void MakeVector3Variable(CSP csp)
 {
     this.mVector3Variable = new Vector3Variable(VariableName, csp, new BoundingBox(new Interval(Min, Max), new Interval(MinY, MaxY), new Interval(MinZ, MaxZ)));
 }
 public MagnitudeConstraint(FloatVariable magnitude, Vector3Variable vector)
     : base(magnitude.CSP)
 {
     this.magnitude = magnitude;
     this.vector = vector;
 }
Example #8
0
 public void MustEqual(Vector3Variable v)
 {
     X.MustEqual(v.X);
     Y.MustEqual(v.Y);
     Z.MustEqual(v.Z);
 }
Example #9
0
 public void MustBePerpendicular(Vector3Variable v)
 {
     Dot(this, v).MustEqual(0);
 }
Example #10
0
 public void MustBeParallel(Vector3Variable v)
 {
     var coefficient = new FloatVariable("parallelCoefficient", CSP, Interval.AllValues);
     this.MustEqual(coefficient * v);
 }
Example #11
0
 public static FloatVariable Dot(Vector3Variable a, Vector3Variable b)
 {
     return a.X.CSP.Memoize(
         "dot",
         () =>
             {
                 var product = new FloatVariable(
                     string.Format("{0} dot {1}", a.Name, b.Name),
                     a.X.CSP,
                     a.X.Value * b.X.Value + a.Y.Value * b.Y.Value + a.Z.Value * b.Z.Value);
                 // ReSharper disable ObjectCreationAsStatement
                 new DotProductConstraint(product, a, b);
                 // ReSharper restore ObjectCreationAsStatement
                 return product;
             },
         a,
         b);
 }
        public void UnitVectorTest()
        {
            var p = new CSP();
            var v = new Vector3Variable("v", p, box);
            v.Magnitude.MustEqual(1);

            for (int count = 0; count < 1000; count++)
            {
                p.NewSolution();
                double magnitude = Math.Sqrt(v.X*v.X+v.Y*v.Y+v.Z*v.Z);
                Assert.IsTrue(MathUtil.NearlyEqual(magnitude, 1), "Magnitude not unity; was: " + magnitude);
            }
        }