Example #1
0
        void CreateChainWithOneFixedEnd(ReferencePoint pt1, int numX, double springDampening, double springRestLength, double springConstant, double mass)
        {
            Particle p;

            XYZ      partXYZ1   = pt1.Position;
            Particle fixedPart1 = particleSystem.makeParticleFromElementID(pt1.Id, mass, pt1.Position, true); // true means 'make fixed'

            XYZ partXYZ2 = partXYZ1 + new XYZ(10, 0, 0);
            //Line tempLine = this.UIDocument.Application.Application.Create.NewLineBound(partXYZ1, partXYZ2);
            XYZ vector = partXYZ2 - partXYZ1;
            XYZ step   = vector.Divide(numX);

            for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts
            {
                //double curveParam = 0;
                XYZ pointOnLine;

                pointOnLine = partXYZ1 + step.Multiply(j);

                if (j == 0) // starting point
                {
                    //curveParam = (double)j / numX;
                    //pointOnLine = tempLine.Evaluate(curveParam, true);
                    p = particleSystem.makeParticle(mass, pointOnLine, true); // make first particle fixed
                }
                else // middle points
                {
                    //curveParam = (double)j / numX;
                    //pointOnLine = tempLine.Evaluate(curveParam, true);
                    p = particleSystem.makeParticle(mass, pointOnLine, false);                                                            // make a new particle along curve at j-th point on line
                    particleSystem.makeSpring(particleSystem.getParticle((j - 1)), p, springRestLength, springConstant, springDampening); //make a new spring and connect it to the last-made point
                }
            }
        }
Example #2
0
        public void DivideScalar()
        {
            var p1 = new XYZ(1, 2, 3);

            Assert.AreEqual(new XYZ(0.5, 1, 1.5), p1.Divided(2));
            p1.Divide(2);
            Assert.AreEqual(new XYZ(0.5, 1, 1.5), p1);
        }
Example #3
0
        /// <summary>
        /// returns XYZ and ZOOM/FOV value
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewport"></param>
        /// <returns></returns>
        public Tuple <ViewOrientation3D, double, string, string> GetViewCoordinates(Document doc, VisualizationInfo viewport)
        {
            string type = ""; //change if i force ortho mode
            double zoom = 0;  //fov or worldscale

            XYZ CameraDirection = new XYZ();
            XYZ CameraUpVector  = new XYZ();
            XYZ CameraViewPoint = new XYZ();

            //retrive the force perspective value


            // IS ORTHOGONAL
            if (viewport.OrthogonalCamera != null)
            {
                if (viewport.OrthogonalCamera.ViewToWorldScale == null || viewport.OrthogonalCamera.CameraViewPoint == null || viewport.OrthogonalCamera.CameraUpVector == null || viewport.OrthogonalCamera.CameraDirection == null)
                {
                    return(null);
                }
                type            = "OrthogonalCamera";
                zoom            = UnitUtils.ConvertToInternalUnits(viewport.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS);
                CameraDirection = GetXYZ(viewport.OrthogonalCamera.CameraDirection.X, viewport.OrthogonalCamera.CameraDirection.Y, viewport.OrthogonalCamera.CameraDirection.Z);
                CameraUpVector  = GetXYZ(viewport.OrthogonalCamera.CameraUpVector.X, viewport.OrthogonalCamera.CameraUpVector.Y, viewport.OrthogonalCamera.CameraUpVector.Z);
                CameraViewPoint = GetXYZ(viewport.OrthogonalCamera.CameraViewPoint.X, viewport.OrthogonalCamera.CameraViewPoint.Y, viewport.OrthogonalCamera.CameraViewPoint.Z);
            }

            else if (viewport.PerspectiveCamera != null)
            {
                if (viewport.PerspectiveCamera.FieldOfView == null || viewport.PerspectiveCamera.CameraViewPoint == null || viewport.PerspectiveCamera.CameraUpVector == null || viewport.PerspectiveCamera.CameraDirection == null)
                {
                    return(null);
                }

                type = "PerspectiveCamera";
                zoom = viewport.PerspectiveCamera.FieldOfView;
                double z1     = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1
                double z      = 18 / Math.Tan(25 / 2 * Math.PI / 180);   //focale, da controllare il 18, vedi PDF
                double factor = z1 - z;

                CameraDirection = GetXYZ(viewport.PerspectiveCamera.CameraDirection.X, viewport.PerspectiveCamera.CameraDirection.Y, viewport.PerspectiveCamera.CameraDirection.Z);
                CameraUpVector  = GetXYZ(viewport.PerspectiveCamera.CameraUpVector.X, viewport.PerspectiveCamera.CameraUpVector.Y, viewport.PerspectiveCamera.CameraUpVector.Z);
                XYZ oldO = GetXYZ(viewport.PerspectiveCamera.CameraViewPoint.X, viewport.PerspectiveCamera.CameraViewPoint.Y, viewport.PerspectiveCamera.CameraViewPoint.Z);
                CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor)));
            }
            else
            {
                return(null);
            }
            // CHAGE VALUES ACCORDING TO BASEPOINT
            //THIS WAS the one with DOC
            ViewOrientation3D orient3d = ConvertBasePoint(CameraViewPoint, CameraDirection, CameraUpVector, true);

            return(new Tuple <ViewOrientation3D, double, string, string>(orient3d, zoom, type, "New View"));
        }
Example #4
0
        public override void Action()
        {
            StringBuilder st = new StringBuilder();
            //Create A Point
            XYZ p1 = new XYZ(1, 1, 1);
            XYZ p2 = new XYZ(1, 1, 10);

            p1.ShowMessageBox();
            //Point Zero
            XYZ zero1 = new XYZ(0, 0, 0);

            zero1.ShowMessageBox();
            XYZ zero2 = XYZ.Zero;

            zero2.ShowMessageBox();
            // Sum
            XYZ add = p1.Add(p2);

            add.ShowMessageBox();
            //Sub
            XYZ sub = p1.Subtract(p2);

            sub.ShowMessageBox();
            // mul
            XYZ multiply = p1.Multiply(5);

            multiply.ShowMessageBox();
            //div
            XYZ divide = p1.Divide(5);

            divide.ShowMessageBox();
            //
            XYZ a = new XYZ(1, 2, 3);

            a.IsZeroLength().ShowMessageBox();
            a.ShowMessageBox();
            //Normal
            XYZ normalize = a.Normalize();

            normalize.ShowMessageBox("normalize");
        }
Example #5
0
        public static XYZ PolyCentPt(PolyLine poly)
        {
            var vertices = poly.GetCoordinates();
            int counter;
            XYZ sumPt = XYZ.Zero;

            if (vertices[0].IsAlmostEqualTo(vertices.Last()))
            {
                counter = vertices.Count() - 1;
            }
            else
            {
                counter = vertices.Count();
            }

            for (int i = 0; i < counter; i++)
            {
                sumPt += vertices[i];
            }
            return(sumPt.Divide(counter));
        }
        /// <summary>
        /// returns XYZ and ZOOM/FOV value
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewport"></param>
        /// <returns></returns>
        public Tuple<ViewOrientation3D, double, string, string> GetViewCoordinates(Document doc, VisualizationInfo viewport)
        {
            string type = ""; //change if i force ortho mode
              double zoom = 0; //fov or worldscale

              XYZ CameraDirection = new XYZ();
              XYZ CameraUpVector = new XYZ();
              XYZ CameraViewPoint = new XYZ();
              //retrive the force perspective value

              // IS ORTHOGONAL
              if (viewport.OrthogonalCamera != null)
              {
            if (viewport.OrthogonalCamera.CameraViewPoint == null || viewport.OrthogonalCamera.CameraUpVector == null || viewport.OrthogonalCamera.CameraDirection == null)
              return null;
            type = "OrthogonalCamera";
            zoom = UnitUtils.ConvertToInternalUnits(viewport.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS);
            CameraDirection = GetXYZ(viewport.OrthogonalCamera.CameraDirection.X, viewport.OrthogonalCamera.CameraDirection.Y, viewport.OrthogonalCamera.CameraDirection.Z);
            CameraUpVector = GetXYZ(viewport.OrthogonalCamera.CameraUpVector.X, viewport.OrthogonalCamera.CameraUpVector.Y, viewport.OrthogonalCamera.CameraUpVector.Z);
            CameraViewPoint = GetXYZ(viewport.OrthogonalCamera.CameraViewPoint.X, viewport.OrthogonalCamera.CameraViewPoint.Y, viewport.OrthogonalCamera.CameraViewPoint.Z);

              }

              else if (viewport.PerspectiveCamera != null)
              {
            if (viewport.PerspectiveCamera.CameraViewPoint == null || viewport.PerspectiveCamera.CameraUpVector == null || viewport.PerspectiveCamera.CameraDirection == null)
              return null;

            type = "PerspectiveCamera";
            zoom = viewport.PerspectiveCamera.FieldOfView;
            double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180);//focale 1
            double z = 18 / Math.Tan(25 / 2 * Math.PI / 180);//focale, da controllare il 18, vedi PDF
            double factor = z1 - z;

            CameraDirection = GetXYZ(viewport.PerspectiveCamera.CameraDirection.X, viewport.PerspectiveCamera.CameraDirection.Y, viewport.PerspectiveCamera.CameraDirection.Z);
            CameraUpVector = GetXYZ(viewport.PerspectiveCamera.CameraUpVector.X, viewport.PerspectiveCamera.CameraUpVector.Y, viewport.PerspectiveCamera.CameraUpVector.Z);
            XYZ oldO = GetXYZ(viewport.PerspectiveCamera.CameraViewPoint.X, viewport.PerspectiveCamera.CameraViewPoint.Y, viewport.PerspectiveCamera.CameraViewPoint.Z);
            CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor)));
              }
              else
            return null;
              // CHAGE VALUES ACCORDING TO BASEPOINT
              //THIS WAS the one with DOC
              ViewOrientation3D orient3d = ConvertBasePoint(CameraViewPoint, CameraDirection, CameraUpVector, true);

              return new Tuple<ViewOrientation3D, double, string, string>(orient3d, zoom, type, "New View");
        }
        public void ValueType_XYZ()
        {
            var p1 = new XYZ(1, 2, 3);
            var p2 = new XYZ(4, 5, 6);

            Assert.AreEqual(14, p1.SquareModulus());
            Assert.AreEqual(Math.Sqrt(14), p1.Modulus());

            Assert.IsTrue(p1.IsEqual(p2, 3));
            Assert.IsFalse(p1.IsEqual(p2, 2.99));

            p2 = p1;
            p2.Add(new XYZ(1, 2, 3));
            Assert.AreEqual(new XYZ(2, 4, 6), p2);
            Assert.AreEqual(new XYZ(2, 4, 6), p1.Added(new XYZ(1, 2, 3)));
            p2 += new XYZ(1, 2, 3);
            Assert.AreEqual(new XYZ(3, 6, 9), p2);

            p2 = new XYZ(1, 2, 3);
            p2.Cross(new XYZ(3, 2, 1));
            Assert.AreEqual(new XYZ(-4, 8, -4), p2);
            Assert.AreEqual(new XYZ(-4, 8, -4), p1.Crossed(new XYZ(3, 2, 1)));

            Assert.AreEqual(Math.Sqrt(96), p1.CrossMagnitude(new XYZ(3, 2, 1)));
            Assert.AreEqual(96, p1.CrossSquareMagnitude(new XYZ(3, 2, 1)));

            p2 = new XYZ(1, 2, 3);
            p2.CrossCross(new XYZ(1, 2, 3), new XYZ(4, 5, 6));
            Assert.AreEqual(new XYZ(-24, -6, 12), p2);
            Assert.AreEqual(new XYZ(-24, -6, 12), p1.CrossCrossed(new XYZ(1, 2, 3), new XYZ(4, 5, 6)));

            p2 = new XYZ(1, 2, 3);
            p2.Divide(2);
            Assert.AreEqual(new XYZ(0.5, 1, 1.5), p2);
            Assert.AreEqual(new XYZ(0.5, 1, 1.5), p1.Divided(2));

            Assert.AreEqual(14, p1.Dot(new XYZ(1, 2, 3)));
            Assert.AreEqual(0, p1.DotCross(new XYZ(4, 5, 6), new XYZ(4, 5, 6)));

            p2 = new XYZ(1, 2, 3);
            p2.Multiply(2);
            Assert.AreEqual(new XYZ(2, 4, 6), p2);
            Assert.AreEqual(new XYZ(2, 4, 6), p1.Multiplied(2));
            Assert.AreEqual(new XYZ(2, 4, 6), p1 * 2);

            p2 = new XYZ(1, 2, 3);
            p2.Multiply(new XYZ(1, 2, 3));
            Assert.AreEqual(new XYZ(1, 4, 9), p2);
            Assert.AreEqual(new XYZ(1, 4, 9), p1.Multiplied(new XYZ(1, 2, 3)));
            Assert.AreEqual(new XYZ(1, 4, 9), p1 * new XYZ(1, 2, 3));

            Mat m1 = new Mat();

            m1.SetRotation(Dir.DZ.Coord, Math.PI / 2);
            p2 = new XYZ(4, 5, 6);
            Assert.AreEqual("-5,4,6", p2.Multiplied(m1).ToString());
            Assert.AreEqual("-5,4,6", (p2 * m1).ToString());
            p2.Multiply(m1);
            Assert.AreEqual("-5,4,6", p2.ToString());

            p2 = new XYZ(1, 2, 3);
            p2.Normalize();
            Assert.IsTrue(p2.IsEqual(new XYZ(0.26726, 0.53452, 0.80178), 0.00001));
            Assert.IsTrue(p1.Normalized().IsEqual(new XYZ(0.26726, 0.53452, 0.80178), 0.00001));

            p2 = new XYZ(1, 2, 3);
            p2.Reverse();
            Assert.AreEqual(new XYZ(-1, -2, -3), p2);
            Assert.AreEqual(new XYZ(-1, -2, -3), p1.Reversed());

            p2 = new XYZ(1, 2, 3);
            p2.Subtract(new XYZ(3, 2, 1));
            Assert.AreEqual(new XYZ(-2, 0, 2), p2);
            Assert.AreEqual(new XYZ(-2, 0, 2), p1.Subtracted(new XYZ(3, 2, 1)));
            Assert.AreEqual(new XYZ(-2, 0, 2), p1 - new XYZ(3, 2, 1));

            p2.SetLinearForm(new XYZ(1, 2, 3), new XYZ(4, 5, 6));
            Assert.AreEqual(new XYZ(5, 7, 9), p2);
            p2.SetLinearForm(2, new XYZ(1, 2, 3), new XYZ(4, 5, 6));
            Assert.AreEqual(new XYZ(6, 9, 12), p2);
            p2.SetLinearForm(2, new XYZ(1, 2, 3), 3, new XYZ(4, 5, 6));
            Assert.AreEqual(new XYZ(14, 19, 24), p2);
            p2.SetLinearForm(2, new XYZ(1, 2, 3), 3, new XYZ(4, 5, 6), new XYZ(7, 8, 9));
            Assert.AreEqual(new XYZ(21, 27, 33), p2);
            p2.SetLinearForm(2, new XYZ(1, 2, 3), 3, new XYZ(4, 5, 6), 4, new XYZ(7, 8, 9));
            Assert.AreEqual(new XYZ(42, 51, 60), p2);
            p2.SetLinearForm(2, new XYZ(1, 2, 3), 3, new XYZ(4, 5, 6), 4, new XYZ(7, 8, 9), new XYZ(10, 11, 12));
            Assert.AreEqual(new XYZ(52, 62, 72), p2);
            //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", gp2.x, gp2.y, gp2.z));
        }
Example #8
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            if (!args[0].IsList)
                throw new Exception("A list of XYZs is required to average.");

            FSharpList<Value> lst = ((Value.List)args[0]).Item;

            XYZ average = new XYZ();
            foreach (Value v in lst)
            {
                XYZ pt = (XYZ)((Value.Container)v).Item;
                average = average.Add(pt);
            }

            average = average.Divide(lst.Count<Value>());
            pts.Add(average);

            return Value.NewContainer(average);
        }
Example #9
0
 /// <summary>
 /// Convert a given point or vector from millimetres to feet.
 /// </summary>
 public static XYZ MmToFoot(XYZ v)
 {
     return(v.Divide(_convertFootToMm));
 }
Example #10
0
 /// <summary>
 /// Convert a given point or vector from milimeters to feet.
 /// </summary>
 public static XYZ MmToFoot(XYZ v)
 {
     return(v.Divide(304.8));
 }