Example #1
0
        public double FrameTick(Point3D angles, Point3D target)
        {
            // Time between two successful frames,
            // which will be nulled on every success in ms
            ElapsedTime = stopwatch.ElapsedTime;
            // Add it to queue and get every parameter middled
            GatherPoints(AngleQueue, angles, ref AngleMiddle, true);
            GatherPoints(TargetQueue, target, ref TargetMiddle, true);

            if (AngleQueue.Count < LENGTH_MIDDLES)
            {
                return(0);
            }

            // Workaround for transition between 350 and 0 degrees
            double xDifference = Math.Abs(angles.X - AngleMiddle.X);
            double yDifference = Math.Abs(angles.Y - AngleMiddle.Y);
            double zDifference = Math.Abs(angles.Z - AngleMiddle.Z);
            double border      = Math.PI / 2;

            if ((xDifference > border) ||
                (yDifference > border) ||
                (zDifference > border))
            {
                AngleMiddle = angles.Clone();
                AngleQueue.Clear();
                for (int i = 0; i < LENGTH_MIDDLES; i++)
                {
                    AngleQueue.Add(angles);
                }
                CurrentAngle = angles.Clone();
            }

            double time = ElapsedTime / (double)IntervalTimerDispatch;
            double dX, dY, dZ;

            // Angles
            dX         = (AngleMiddle.X - CurrentAngle.X) / time;
            dY         = (AngleMiddle.Y - CurrentAngle.Y) / time;
            dZ         = (AngleMiddle.Z - CurrentAngle.Z) / time;
            DeltaAngle = new Point3D(dX, dY, dZ);

            // Target
            dX          = (TargetMiddle.X - CurrentTarget.X) / time;
            dY          = (TargetMiddle.Y - CurrentTarget.Y) / time;
            dZ          = (TargetMiddle.Z - CurrentTarget.Z) / time;
            DeltaTarget = new Point3D(dX, dY, dZ);

            Kfade = K_INIT;

            return(dY);
        }
Example #2
0
        private void DrawDirectional(out Entity drawnLight, out LeaderAndText lightName)
        {
            // sets start position of the drawn light
            Point3D startPoint = (Point3D)CenterScene.Clone();

            startPoint.TransformBy(new Translation(Light.Direction * (-Radius)));

            // draws directional light like an arrow
            drawnLight             = Mesh.CreateArrow(startPoint, Light.Direction, 0.2, 5, 0.6, 3, 10, Mesh.natureType.Smooth, Mesh.edgeStyleType.Free);
            drawnLight.ColorMethod = colorMethodType.byEntity;

            // draws name label
            lightName = new LeaderAndText(startPoint + new Vector3D(0, 0, 0.2), "Light " + NumLight,
                                          new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 15));
        }
Example #3
0
        public bool UpdateStep()
        {
            if ((DeltaAngle != null) && (DeltaTarget != null) && (Kfade > 0))
            {
                double  incX, incY, incZ;
                Point3D deltaAngleClone = DeltaAngle.Clone();
                // Angles
                incX            = deltaAngleClone.X;
                incY            = deltaAngleClone.Y;
                incZ            = deltaAngleClone.Z;
                CurrentAngle.X += (incX * Kfade);
                CurrentAngle.Y += (incY * Kfade);
                CurrentAngle.Z += (incZ * Kfade);

                // Target
                Point3D deltaTargetClone = DeltaTarget.Clone();
                incX             = deltaTargetClone.X;
                incY             = deltaTargetClone.Y;
                incZ             = deltaTargetClone.Z;
                CurrentTarget.X += (incX * Kfade);
                CurrentTarget.Y += (incY * Kfade);
                CurrentTarget.Z += (incZ * Kfade);

                Kfade -= K_DECR;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        public override bool IsInFrustum(FrustumParams data, Point3D center, double radius)
        {
            Point3D transfCenter = (Point3D)center.Clone();

            if (t != 0 && rotationAxis != null)
            {
                // Get the BlockReference full transformation
                Transformation brFullTransf = GetFullTransformation(data.Blocks);

                // Apply the inverse of the full transformation to the center to bring it back to original position
                // It's necessary because in the MoveTo() the first transformation is applied before tha base method is called.
                Transformation tr = (Transformation)brFullTransf.Clone();
                tr.Invert();
                transfCenter.TransformBy(tr);

                // Compute a transformation equals to the transformation applied in the MoveTo method
                Translation translation1 = new Translation(t * translationVect.X, t * translationVect.Y, t * translationVect.Z);
                Translation translation2 = new Translation(firstPt.X, firstPt.Y, firstPt.Z);
                Translation translation3 = new Translation(-firstPt.X, -firstPt.Y, -firstPt.Z);
                Rotation    rotation     = new Rotation(Utility.DegToRad(t * rotationAngle), rotationAxis);

                Transformation customTransform = translation1 * brFullTransf;
                customTransform = customTransform * translation2;
                customTransform = customTransform * rotation;
                customTransform = customTransform * translation3;

                // Apply transformation to the center
                transfCenter.TransformBy(customTransform);
            }

            // Call the base with the transformed "center", to avoid undesired clipping
            return(base.IsInFrustum(data, transfCenter, radius));
        }
Example #5
0
        public SetupChange_OptimizedCoordinate(Point3D _nominalCoord, Point3D _upperLimit, Point3D _lowerLimit /*, int _bitSize*/)
        {
            NominalCoordinates = _nominalCoord;

            OptimizedCoordinates = NominalCoordinates.Clone() as Point3D;

            UpperCoordinateLimit = _upperLimit;

            LowerCoordinateLimit = _lowerLimit;
        }
Example #6
0
 public Slice(VolumeData volume, Point3D topLeft, Vector3D rowDir, Vector3D colDir, int rows, int cols, double spacing)
 {
     _volume         = volume;
     TopLeft         = topLeft.Clone();
     RowDirection    = rowDir.Clone();
     ColumnDirection = colDir.Clone();
     Rows            = rows;
     Columns         = cols;
     Spacing         = spacing;
     CalculateCut();
 }
        /// <summary>
        /// Overloaded Constructor
        /// </summary>
        /// <param name="_nominalCoord">Nominal Coordinates of the Adjuster</param>
        /// <param name="_upperLimit">Upper Limit of Adjuster's Coordinates</param>
        /// <param name="_lowerLimit">Lower Limit of the Adjuster's Coordinates</param>
        /// <param name="_bitSize">Bit size of the Adjuster which needs to be passed to Optimizer</param>
        public KO_AdjToolParams(Point3D _nominalCoord, Point3D _upperLimit, Point3D _lowerLimit, int _bitSize)
        {
            NominalCoordinates = _nominalCoord;

            OptimizedCoordinates = NominalCoordinates.Clone() as Point3D;

            UpperCoordinateLimit = _upperLimit;

            LowerCoordinateLimit = _lowerLimit;

            BitSize = _bitSize;
        }
Example #8
0
        public void Point3D()
        {
            //Do various Point method calls to cover the point class with sufficient testing
            Point3D p0 = new Point3D();
            Point   p  = new Point(23, 21);
            Point3D p1 = new Point3D(450, 120, 34);
            Point3D p2 = new Point3D(p, 94);

            Assert.IsTrue(p0.IsEmpty());
            Assert.IsFalse(p1.IsEmpty());
            Assert.IsFalse(p2.IsEmpty());

            Assert.AreNotEqual(p, p2);
            Assert.AreEqual(94, p2.Z);

            Assert.AreNotSame(p1.Clone(), p1);
            p0     = p1.Clone();
            p0.X  += 100;
            p0.Y   = 150;
            p0.Z  += 499;
            p0[2] += p0[2];
            Assert.AreEqual(new Point3D(550, 150, 1066), p0);
            Assert.AreEqual(p2.AsPoint(), p2.GetBoundingBox().Min);
            Assert.AreEqual(p2.AsPoint(), p2.GetBoundingBox().Max);
            Assert.AreEqual(3, p2.NumOrdinates);
            Assert.AreEqual(new Point3D(-27, 1, 123), p2 + new Point3D(-50, -20, 29));
            Assert.AreEqual(new Point(73, 1), p2 - new Point(-50, 20));
            Assert.AreEqual(new Point3D(46, 42, 188), p2 * 2);
            Assert.AreEqual(0, p2.Dimension);
            Assert.AreEqual(23, p2[0]);
            Assert.AreEqual(21, p2[1]);
            Assert.AreEqual(94, p2[2]);
            Assert.IsNull(p2.Boundary());
            Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.Z.GetHashCode() ^ p2.IsEmpty().GetHashCode(),
                            p2.GetHashCode());
            Assert.Less(p2.CompareTo(p1), 0);
            Assert.Greater(p1.CompareTo(p2), 0);
            Assert.AreEqual(0, p2.CompareTo(new Point3D(23, 21, 94)));
            Assert.AreEqual(0, p2.CompareTo(new Point(23, 21)));
        }
Example #9
0
		public void Point3D()
		{
			//Do various Point method calls to cover the point class with sufficient testing
			Point3D p0 = new Point3D();
			Point p = new Point(23, 21);
			Point3D p1 = new Point3D(450, 120, 34);
			Point3D p2 = new Point3D(p, 94);
			Assert.IsTrue(p0.IsEmpty());
			Assert.IsFalse(p1.IsEmpty());
			Assert.IsFalse(p2.IsEmpty());

			Assert.AreNotEqual(p, p2);
			Assert.AreEqual(94, p2.Z);

			Assert.AreNotSame(p1.Clone(), p1);
			p0 = p1.Clone();
			p0.X += 100;
			p0.Y = 150;
			p0.Z += 499;
			p0[2] += p0[2];
			Assert.AreEqual(new Point3D(550, 150, 1066), p0);
			Assert.AreEqual(p2.AsPoint(), p2.GetBoundingBox().Min);
			Assert.AreEqual(p2.AsPoint(), p2.GetBoundingBox().Max);
			Assert.AreEqual(3, p2.NumOrdinates);
			Assert.AreEqual(new Point3D(-27, 1, 123), p2 + new Point3D(-50, -20, 29));
			Assert.AreEqual(new Point(73, 1), p2 - new Point(-50, 20));
			Assert.AreEqual(new Point3D(46, 42, 188), p2*2);
			Assert.AreEqual(0, p2.Dimension);
			Assert.AreEqual(23, p2[0]);
			Assert.AreEqual(21, p2[1]);
			Assert.AreEqual(94, p2[2]);
			Assert.IsNull(p2.Boundary());
			Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.Z.GetHashCode() ^ p2.IsEmpty().GetHashCode(),
			                p2.GetHashCode());
			Assert.Less(p2.CompareTo(p1), 0);
			Assert.Greater(p1.CompareTo(p2), 0);
			Assert.AreEqual(0, p2.CompareTo(new Point3D(23, 21, 94)));
			Assert.AreEqual(0, p2.CompareTo(new Point(23, 21)));
		}
Example #10
0
        private static List <Point3D> BuildWire(double length)
        {
            List <Point3D> wires = new List <Point3D>();

            Point3D p1 = new Point3D(-20, 0, 0);
            Point3D p2 = Point3D.Origin;

            wires.Add(new Point3D(0, 0, 0));
            wires.Add(new Point3D(0, 0, length));

            wires.Add(p1);
            wires.Add(p2);

            int    numArrows = 10;
            double step      = length / numArrows;

            Point3D ptArrow1 = new Point3D(-4, 0, -2);
            Point3D ptArrow2 = new Point3D(-4, 0, 2);

            Vector3D dir = Vector3D.AxisZ;

            for (int i = 0; i < numArrows + 1; i++)
            {
                Point3D offset  = dir * step * i;
                Point3D newPos  = p1 + offset;
                Point3D newPos2 = p2 + offset;

                wires.Add(newPos);
                wires.Add((Point3D)newPos2.Clone());
                wires.Add((Point3D)newPos2.Clone());
                wires.Add(newPos2 + ptArrow1);
                wires.Add((Point3D)newPos2.Clone());
                wires.Add(newPos2 + ptArrow2);
            }

            return(wires);
        }
Example #11
0
        public static float CheckIntersections(Creature creature, short heading, Point3D moveVector, float distance)
        {
            if (distance <= 0f)
            {
                return(0f);
            }

            WorldPosition targetPosition = moveVector.Clone().Add(creature.Position).ToWorldPosition();

            double minDistance = distance;

            List <Creature> around = Global.VisibleService.FindTargets(creature, creature.Position, distance + 40, TargetingAreaType.All);

            for (int x = 0; x < around.Count; x++)
            {
                if (around[x] == creature)
                {
                    continue;
                }

                short diff = Geom.GetAngleDiff(heading, Geom.GetHeading(creature.Position, around[x].Position));
                if (diff > 90)
                {
                    continue;
                }

                double d = Geom.DistanceToLine(around[x].Position, creature.Position, targetPosition);

                if (d > 40)
                {
                    continue;
                }

                d = creature.Position.DistanceTo(around[x].Position) - 40;

                if (d <= 0)
                {
                    return(0f);
                }

                if (d < minDistance)
                {
                    minDistance = d;
                }
            }

            return((float)(minDistance / distance));
        }
Example #12
0
        private Point3D GetSnappedPoint(System.Drawing.Point mousePos, Plane plane, IList <Point3D> pts, int indexToCompare)
        {
            // if the mouse in within 10 pixels of the first curve point, return the first point
            if (pts.Count > 0)
            {
                Point3D ptToSnap     = pts[indexToCompare];
                Point3D ptSnapScreen = WorldToScreen(ptToSnap);

                Point2D current = new Point2D(mousePos.X, Size.Height - mousePos.Y);

                if (Point2D.Distance(current, ptSnapScreen) < 10)
                {
                    return((Point3D)ptToSnap.Clone());
                }
            }

            Point3D pt;

            ScreenToPlane(mousePos, plane, out pt);
            return(pt);
        }
        /// <summary>
        /// Method to Initialize the <see cref="InboardAssembly"/> and <see cref="OutboardAssembly"/> <see cref="Dictionary{String, Point3D}"/>s
        /// </summary>
        public void Initialize_Dictionary()
        {
            OutboardAssembly = new Dictionary <string, Point3D>();

            InboardAssembly = new Dictionary <string, Point3D>();



            ///---INBOARD POINTS

            ///Upper Front
            InboardAssembly.Add(CoordinateOptions.UpperFront.ToString(), UpperFront);

            ///Upper Rear
            InboardAssembly.Add(CoordinateOptions.UpperRear.ToString(), UpperRear);

            ///Lower Front
            InboardAssembly.Add(CoordinateOptions.LowerFront.ToString(), LowerFront);

            ///Lower Rear
            InboardAssembly.Add(CoordinateOptions.LowerRear.ToString(), LowerRear);

            ///Toe Link Inboard
            InboardAssembly.Add(CoordinateOptions.ToeLinkInboard.ToString(), ToeLinkInboard);

            ///Pushrod Inboard
            InboardAssembly.Add(CoordinateOptions.PushrodInboard.ToString(), PushrodInboard);

            ///Damper BellCrank
            InboardAssembly.Add(CoordinateOptions.DamperBellCrank.ToString(), DamperBellCrank);

            //ARB BellCrank
            InboardAssembly.Add(CoordinateOptions.ARBBellCrank.ToString(), ARBBellCrank);

            ///Damper Chassis Shock Mount
            InboardAssembly.Add(CoordinateOptions.DamperShockMount.ToString(), DamperShockMount);

            //ARB End Point on Chassis
            InboardAssembly.Add(CoordinateOptions.ARBEndPointChassis.ToString(), ARB_EndPoint_Chassis);

            //ARB Droop Link Point on Lever
            InboardAssembly.Add(CoordinateOptions.ARBLeverEndPoint.ToString(), ARB_DroopLink_LeverPoint);

            ///Rocker Pivot Point
            InboardAssembly.Add(CoordinateOptions.BellCrankPivot.ToString(), Rocker_Center);

            ///---OUTBOARD POINTS


            ///UBJ
            OutboardAssembly.Add(CoordinateOptions.UBJ.ToString(), UBJ);

            ///Top Camber Mount
            OutboardAssembly.Add(CoordinateOptions.TopCamberMount.ToString(), /*UBJ.Clone() as Point3D*/ TopCamberMount);

            ///Pushrod Outboard
            OutboardAssembly.Add(CoordinateOptions.PushrodOutboard.ToString(), PushrodOutboard);

            ///LBJ
            OutboardAssembly.Add(CoordinateOptions.LBJ.ToString(), LBJ);

            ///Bottom Camber Mount
            OutboardAssembly.Add(CoordinateOptions.BottomCamberMount.ToString(), BottomCamberMount);

            ///Wheel Center
            OutboardAssembly.Add(CoordinateOptions.WheelCenter.ToString(), WheelCenter);

            ///Wheel Spindle End
            OutboardAssembly.Add(CoordinateOptions.WheelSpindleEnd.ToString(), new Point3D(WheelCenter.X + 157, WheelCenter.Y, WheelCenter.Z));

            ///Toe Link Outboard
            OutboardAssembly.Add(CoordinateOptions.ToeLinkOutboard.ToString(), ToeLinkOutboard);

            ///Contact Patch
            OutboardAssembly.Add("ContactPatch", ContactPatch);

            Round_DictionaryValues();

            AxisLines_WheelCenter = new Dictionary <string, Line>();

            if (UBJ != null && LBJ != null && WheelCenter != null && WcEnd != null)
            {
                AxisLines_WheelCenter.Add("SteeringAxis", new Line(UBJ.Clone() as Point3D, LBJ.Clone() as Point3D));

                AxisLines_WheelCenter.Add("SteeringAxis_Ref", new Line(UBJ.Clone() as Point3D, LBJ.Clone() as Point3D));

                AxisLines_WheelCenter.Add("LateralAxis_WheelCenter", new Line(WheelCenter.Clone() as Point3D, new Point3D(WheelCenter.X + 100, WheelCenter.Y, WheelCenter.Z)));

                AxisLines_WheelCenter.Add("WheelSpindle", new Line(WheelCenter.Clone() as Point3D, WcEnd.Clone() as Point3D));

                AxisLines_WheelCenter.Add("WheelSpindle_Ref", new Line(WheelCenter.Clone() as Point3D, WcEnd.Clone() as Point3D));

                AxisLines_WheelCenter.Add("VerticalAxis_WheelCenter", new Line(WheelCenter.Clone() as Point3D, new Point3D(WheelCenter.X, WheelCenter.Y + 100, WheelCenter.Z)));

                AxisLines_WheelCenter.Add("LongitudinalAxis_WheelCenter", new Line(WheelCenter.Clone() as Point3D, new Point3D(WheelCenter.X, WheelCenter.Y, WheelCenter.Z + 100)));
            }
        }
Example #14
0
 public Line3D(Point3D p, Vector3D v)
 {
     Point  = p.Clone();
     Vector = v.Clone();
 }
        /// <summary>
        /// Method to Initialize ALL the <see cref="Point3D"/>s using a <see cref="SuspensionCoordinatesMaster"/> object
        /// </summary>
        public void Initialize_Points(SuspensionCoordinatesMaster _scm)
        {
            OutboardAssembly = new Dictionary <string, Point3D>();

            InboardAssembly = new Dictionary <string, Point3D>();

            ///---INBOARD POINTS

            ///Upper Front
            UpperFront = new Point3D(_scm.A1x, _scm.A1y, _scm.A1z);
            InboardAssembly.Add(CoordinateOptions.UpperFront.ToString(), UpperFront);

            ///Upper Rear
            UpperRear = new Point3D(_scm.B1x, _scm.B1y, _scm.B1z);
            InboardAssembly.Add(CoordinateOptions.UpperRear.ToString(), UpperRear);

            ///Lower Front
            LowerFront = new Point3D(_scm.D1x, _scm.D1y, _scm.D1z);
            InboardAssembly.Add(CoordinateOptions.LowerFront.ToString(), LowerFront);

            ///Lower Rear
            LowerRear = new Point3D(_scm.C1x, _scm.C1y, _scm.C1z);
            InboardAssembly.Add(CoordinateOptions.LowerRear.ToString(), LowerRear);

            ///Toe Link Inboard
            ToeLinkInboard = new Point3D(_scm.N1x, _scm.N1y, _scm.N1z);
            InboardAssembly.Add(CoordinateOptions.ToeLinkInboard.ToString(), ToeLinkInboard);

            ///Pushrod Inboard
            PushrodInboard = new Point3D(_scm.H1x, _scm.H1y, _scm.H1z);
            InboardAssembly.Add(CoordinateOptions.PushrodInboard.ToString(), PushrodInboard);

            ///Damper BellCrank
            DamperBellCrank = new Point3D(_scm.J1x, _scm.J1y, _scm.J1z);
            InboardAssembly.Add(CoordinateOptions.DamperBellCrank.ToString(), DamperBellCrank);

            ///Damper Chassis Shock Mount
            DamperShockMount = new Point3D(_scm.JO1x, _scm.JO1y, _scm.JO1z);
            InboardAssembly.Add(CoordinateOptions.DamperShockMount.ToString(), DamperShockMount);


            ///---OUTBOARD POINTS


            ///UBJ
            UBJ = new Point3D(_scm.F1x, _scm.F1y, _scm.F1z);
            OutboardAssembly.Add(CoordinateOptions.UBJ.ToString(), UBJ);

            ///Top Camber Mount
            TopCamberMount = new Point3D(_scm.TCM1x, _scm.TCM1y, _scm.TCM1z);
            OutboardAssembly.Add(CoordinateOptions.TopCamberMount.ToString(), /*UBJ.Clone() as Point3D*/ TopCamberMount);

            ///Pushrod Outboard
            PushrodOutboard = new Point3D(_scm.G1x, _scm.G1y, _scm.G1z);
            OutboardAssembly.Add(CoordinateOptions.PushrodOutboard.ToString(), PushrodOutboard);

            ///LBJ
            LBJ = new Point3D(_scm.E1x, _scm.E1y, _scm.E1z);
            OutboardAssembly.Add(CoordinateOptions.LBJ.ToString(), LBJ);

            ///Bottom Camber Mount
            BottomCamberMount = new Point3D(_scm.BCM1x, _scm.BCM1y, _scm.BCM1z);
            OutboardAssembly.Add(CoordinateOptions.BottomCamberMount.ToString(), BottomCamberMount);

            ///Wheel Center
            WheelCenter = new Point3D(_scm.K1x, _scm.K1y, _scm.K1z);
            OutboardAssembly.Add(CoordinateOptions.WheelCenter.ToString(), WheelCenter);

            ///Wheel Spindle End
            WcEnd = new Point3D(_scm.L1x, _scm.L1y, _scm.L1z);
            OutboardAssembly.Add("WcEnd", WcEnd);

            ///Toe Link Outboard
            ToeLinkOutboard = new Point3D(_scm.M1x, _scm.M1y, _scm.M1z);
            OutboardAssembly.Add(CoordinateOptions.ToeLinkOutboard.ToString(), ToeLinkOutboard);

            ///Contact Patch
            ContactPatch = new Point3D(_scm.W1x, _scm.W1x, _scm.W1z);
            OutboardAssembly.Add("ContactPatch", ContactPatch);


            AxisLines_WheelCenter = new Dictionary <string, Line>();

            AxisLines_WheelCenter.Add("SteeringAxis", new Line(UBJ.Clone() as Point3D, LBJ.Clone() as Point3D));

            AxisLines_WheelCenter.Add("SteeringAxis_Ref", new Line(UBJ.Clone() as Point3D, LBJ.Clone() as Point3D));

            AxisLines_WheelCenter.Add("LateralAxis_WheelCenter", new Line(WheelCenter.Clone() as Point3D, new Point3D(WheelCenter.X + 100, WheelCenter.Y, WheelCenter.Z)));

            AxisLines_WheelCenter.Add("WheelSpindle", new Line(WheelCenter.Clone() as Point3D, WcEnd.Clone() as Point3D));

            AxisLines_WheelCenter.Add("WheelSpindle_Ref", new Line(WheelCenter.Clone() as Point3D, WcEnd.Clone() as Point3D));

            AxisLines_WheelCenter.Add("VerticalAxis_WheelCenter", new Line(WheelCenter.Clone() as Point3D, new Point3D(WheelCenter.X, WheelCenter.Y + 100, WheelCenter.Z)));

            AxisLines_WheelCenter.Add("LongitudinalAxis_WheelCenter", new Line(WheelCenter.Clone() as Point3D, new Point3D(WheelCenter.X, WheelCenter.Y, WheelCenter.Z + 100)));
        }
Example #16
0
        /// <summary>
        /// Method to construct the <see cref="PlaneRED"/> and the <see cref="PlaneRED2"/>
        /// </summary>
        private void ConstructPlaneREDs()
        {
            ///<summary>Constructing the <see cref="PlaneRED"/> using the <see cref="InstantAxis"/> and the <see cref="PointA"/></summary>
            PlaneRED = new Plane(InstantAxis.StartPoint.Clone() as Point3D, InstantAxis.EndPoint.Clone() as Point3D, PointA.Clone() as Point3D);
            ///<summary>Constructing the Line of the <see cref=PlaneRED"/> needed for the angle</summary>
            LineForAngle_PlaneRED = new Line(InstantAxis.MidPoint.Clone() as Point3D, PointA.Clone() as Point3D);

            ///<summary>Computing the <see cref="Angle"/> between the <see cref="PlaneRED"/> and the <see cref="Bisector1"/></summary>
            Angle_Bis1_PlaneRED = SetupChangeDatabase.AngleInRequiredView(Custom3DGeometry.GetMathNetVector3D(LineForAngle_PlaneRED), Custom3DGeometry.GetMathNetVector3D(Bisector1),
                                                                          Custom3DGeometry.GetMathNetVector3D(new Line(InstantAxis.StartPoint, InstantAxis.EndPoint)));

            ///<summary>Cloning <see cref="PlaneRED"/> onto <see cref="PlaneRED2"/> and creating its line</summary>
            PlaneRED2 = PlaneRED.Clone() as Plane;
            LineForAngle_PlaneRed2 = LineForAngle_PlaneRED.Clone() as Line;

            ///<summary>Rotating the <see cref="PlaneRED2"/> and its <see cref="LineForAngle_PlaneRed2"/> by an amount equal to twice the Angle b/w <see cref="Bisector1"/> and <see cref="PlaneRED"/></summary>
            PlaneRED2.Rotate(-Angle_Bis1_PlaneRED.Radians * 2, new Vector3D(InstantAxis.StartPoint.Clone() as Point3D, InstantAxis.EndPoint.Clone() as Point3D), InstantAxis.MidPoint);
            LineForAngle_PlaneRed2.Rotate(-Angle_Bis1_PlaneRED.Radians * 2, new Vector3D(InstantAxis.StartPoint.Clone() as Point3D, InstantAxis.EndPoint.Clone() as Point3D), InstantAxis.StartPoint);

            PlanarEntity PlaneRED_Ent  = new PlanarEntity(PlaneRED);
            PlanarEntity PlaneRED2_Ent = new PlanarEntity(PlaneRED2);
            //cad1.viewportLayout1.Entities.AddRange(new Entity[] { PlaneRED_Ent, PlaneRED2_Ent });
        }
Example #17
0
 public Line3D(Point3D p1, Point3D p2)
 {
     Point  = p1.Clone();
     Vector = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
 }
Example #18
0
        private void SendControlParameters(List <Point3D> ViewPoint, byte[, ,] ImgDataToFlash)
        {
            List <Point3D> ViewDescriptor = new List <Point3D>();

            if (GlobalProperties.ViewPointMode)
            {
                ViewDescriptor.Add(ViewPoint[0]);
                ViewDescriptor.Add(ViewPoint[1]);
                ViewDescriptor.Add(ViewPoint[2]);
            }

            Visualization.ProjectDescriptor(ViewPoint, CenterProjXY, imgR, FrameRows);
            List <Point3D> currentOrientation = calibrateModule.RecalcOrientation(ViewPoint);

            if (GlobalProperties.ViewPointMode)
            {
                if (checkBoxPan.Checked)
                {
                    ViewDescriptor.Add(currentOrientation[0].Clone());
                }
                else
                {
                    ViewDescriptor.Add(new Point3D(0, 0, 0));
                }

                ViewDescriptor.Add(currentOrientation[1]);
                ViewDescriptor.Add(currentOrientation[2]);
                ViewDescriptor.Add(currentOrientation[3]);
            }

            // Recalibrate every frame
            if (calibrateModule.p0translation != null)
            {
                // Move current frame with translation of calibration frame
                Geometry.p_add(currentOrientation, calibrateModule.p0translation, -1);

                // Rotation of whole current coordinate system with parameters of calibration
                Geometry.p_rotY(currentOrientation, calibrateModule.ySinCosAxis, -1);
                Geometry.p_rotZ(currentOrientation, calibrateModule.zSinCosAxis, -1);
                Geometry.p_rotX(currentOrientation, calibrateModule.xSinCosAxis, -1);

                // Move back current frame with translation of calibration frame
                Geometry.p_add(currentOrientation, calibrateModule.p0translation, 1);
                CalibrationCopy = Geometry.CloneList(calibrateModule.CalibrationOrientation[0]);


                // Move current frame to origin and calculate align parameters
                TranslationCurr = currentOrientation[0].Clone();
                Geometry.p_add(currentOrientation, currentOrientation[0].Clone(), -1);
                currParam = Geometry.align_calc_pars(
                    currentOrientation[0],
                    currentOrientation[1],
                    currentOrientation[2]);

                // Rotate Current frame coordinate system to coincide with XYZ
                ySinCosCurr = Geometry.calc_rotY(currentOrientation[1]);
                Geometry.p_rotY(currentOrientation, ySinCosCurr, -1);

                zSinCosCurr = Geometry.calc_rotZ(currentOrientation[1]);
                Geometry.p_rotZ(currentOrientation, zSinCosCurr, -1);

                xSinCosCurr = Geometry.calc_rotX(currentOrientation[2]);
                Geometry.p_rotX(currentOrientation, xSinCosCurr, -1);

                //Align current orientation with parameters of calibration and current frame parameters before rotation
                Geometry.align(currentOrientation, currParam, calibrateModule.AlignParamCalibration);

                // Translate back with current frame translation
                Geometry.p_add(currentOrientation, TranslationCurr.Clone(), 1);

                //VisualizeCoordinateSystem(currentOrientation, true);
            }

            OnSendParameters(ViewDescriptor, currentOrientation);

            if (calibrateModule.IsCalibrate)
            {
                calibrateModule.CalcCalibration(ViewPoint, ImgDataToFlash);
            }

            if ((checkBoxCharts.Checked) && (!chartPoint.IsDisposed))
            {
                //    chartPt1.UpdateChart(ViewPoint[1].X, ViewPoint[1].Y, ViewPoint[1].Z);
                //    chartPtD1.UpdateChart(dArr1.X, dArr1.Y, dArr1.Z);
            }

            // Call subscribers for this event
            //if (checkBoxDrawViewPoint.Checked && (DrawViewPoint != null))
            //    DrawViewPoint(this, new DrawViewPointEventArgs(ViewPoint, true));
        }
Example #19
0
 public Segment3D(Point3D a, Point3D b)
 {
     A = a.Clone();
     B = b.Clone();
 }
Example #20
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var mousePos = RenderContextUtility.ConvertPoint(GetMousePosition(e));

            this.selEntityIndex = GetEntityUnderMouseCursor(mousePos);

            if (waitingForSelection)
            {
                if (this.selEntityIndex != -1)
                {
                    if (selEntity == null || drawingAngularDim)
                    {
                        this.selEntity = this.Entities[selEntityIndex];
                        if (activeOperationLabel != "")
                        {
                            this.selEntity.Selected = true;
                        }
                    }

                    // drawingAngularDim from lines needs more than one selection
                    if (!drawingAngularDim || this.Entities[selEntityIndex] is Arc)
                    {
                        waitingForSelection = false;
                    }
                }
            }

            if (GetToolBar().Contains(mousePos))
            {
                base.OnMouseDown(e);

                return;
            }

            #region Handle LMB Clicks
            if (ActionMode == actionType.None && e.ChangedButton == MouseButton.Left)
            {
                // we need to skip adding points for entity selection click
                editingMode = doingOffset || doingMirror || doingExtend || doingTrim || doingFillet || doingChamfer || doingTangents;

                ScreenToPlane(mousePos, plane, out current);

                if (objectSnapEnabled && snapPoint != null)
                {
                    if (!(editingMode && firstClick))
                    {
                        points.Add(snapPoint);
                    }
                }
                else if (IsPolygonClosed())//control needed to close curve and polyline when cursor is near the starting point of polyline or curve
                {
                    //if the distance from current point and first point stored is less than given threshold
                    points.Add((Point3D)points[0].Clone()); //the point to add to points is the first point stored.
                    current = (Point3D)points[0].Clone();
                }
                else if (gridSnapEnabled)
                {
                    if (!(editingMode && firstClick))
                    {
                        SnapToGrid(ref current);
                        points.Add(current);
                    }
                }
                else
                {
                    if (!(editingMode && firstClick))
                    {
                        points.Add(current);
                    }
                }
                firstClick = false;

                // If drawing points, create and add new point entity on each LMB click
                if (drawingPoints)
                {
                    devDept.Eyeshot.Entities.Point point;

                    if (objectSnapEnabled && snapPoint != null)
                    {
                        point = new devDept.Eyeshot.Entities.Point(snap);
                    }
                    else
                    {
                        point = new devDept.Eyeshot.Entities.Point(current);
                    }

                    AddAndRefresh(point, ActiveLayerName);
                }
                else if (drawingText)
                {
                    devDept.Eyeshot.Entities.Text text = new Text(current, "Sample Text", 5);
                    AddAndRefresh(text, ActiveLayerName);
                }
                else if (drawingLeader)
                {
                    if (points.Count == 3)
                    {
                        Leader leader = new Leader(Plane.XY, points);
                        leader.ArrowheadSize = 3;
                        AddAndRefresh(leader, ActiveLayerName);
                        devDept.Eyeshot.Entities.Text text = new Text((Point3D)current.Clone(), "Sample Text", leader.ArrowheadSize);
                        AddAndRefresh(text, ActiveLayerName);

                        drawingLeader = false;
                    }
                }
                // If LINE drawing is finished, create and add line entity to model
                else if (drawingLine && points.Count == 2)
                {
                    Line line = new Line(points[0], points[1]);
                    AddAndRefresh(line, ActiveLayerName);
                    drawingLine = false;
                }
                // If CIRCLE drawing is finished, create and add a circle entity to model
                else if (drawingCircle && points.Count == 2)
                {
                    Circle circle = new Circle(drawingPlane, drawingPlane.Origin, radius);
                    AddAndRefresh(circle, ActiveLayerName);

                    drawingCircle = false;
                }
                // If ARC drawing is finished, create and add an arc entity to model
                // Input - Center and two end points
                else if (drawingArc && points.Count == 3)
                {
                    Arc arc = new Arc(drawingPlane, drawingPlane.Origin, radius, 0, arcSpanAngle);
                    AddAndRefresh(arc, ActiveLayerName);

                    drawingArc = false;
                }
                // If drawing ellipse, create and add ellipse entity to model
                // Inputs - Ellipse center, End of first axis, End of second axis
                else if (drawingEllipse && points.Count == 3)
                {
                    Ellipse ellipse = new Ellipse(drawingPlane, drawingPlane.Origin, radius, radiusY);
                    AddAndRefresh(ellipse, ActiveLayerName);

                    drawingEllipse = false;
                }
                // If EllipticalArc drawing is finished, create and add EllipticalArc entity to model
                // Input - Ellipse center, End of first axis, End of second axis, end point
                else if (drawingEllipticalArc && points.Count == 4)
                {
                    EllipticalArc ellipticalArc = new EllipticalArc(drawingPlane, drawingPlane.Origin, radius, radiusY, 0, arcSpanAngle, true);
                    AddAndRefresh(ellipticalArc, ActiveLayerName);

                    drawingEllipticalArc = false;
                }
                else if (drawingLinearDim && points.Count == 3)
                {
                    LinearDim linearDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight);
                    AddAndRefresh(linearDim, ActiveLayerName);

                    drawingLinearDim = false;
                }
                else if (drawingAlignedDim && points.Count == 3)
                {
                    LinearDim alignedDim = new LinearDim(drawingPlane, points[0], points[1], current, dimTextHeight);
                    AddAndRefresh(alignedDim, ActiveLayerName);

                    drawingAlignedDim = false;
                }
                else if (drawingOrdinateDim && points.Count == 2)
                {
                    OrdinateDim ordinateDim = new OrdinateDim(Plane.XY, points[0], points[1], drawingOrdinateDimVertical, dimTextHeight);
                    AddAndRefresh(ordinateDim, ActiveLayerName);

                    drawingOrdinateDim = false;
                }
                else if ((drawingRadialDim || drawingDiametricDim) && points.Count == 2)
                {
                    if (selEntity is Circle)
                    {
                        Circle circle = selEntity as Circle;

                        // ensures that radialDim plane has always the correct normal
                        Circle orientedCircle = new Circle(Plane.XY, circle.Center, circle.Radius);

                        if (drawingRadialDim)
                        {
                            RadialDim radialDim = new RadialDim(orientedCircle, points[points.Count - 1], dimTextHeight);
                            AddAndRefresh(radialDim, ActiveLayerName);
                            drawingRadialDim = false;
                        }
                        else
                        {
                            DiametricDim diametricDim = new DiametricDim(orientedCircle, points[points.Count - 1], dimTextHeight);
                            AddAndRefresh(diametricDim, ActiveLayerName);
                            drawingDiametricDim = false;
                        }
                    }
                }
                else if (drawingAngularDim)
                {
                    if (!drawingAngularDimFromLines)
                    {
                        if (selEntity is Arc && points.Count == 2 && !drawingQuadrantPoint)
                        {
                            Arc     arc        = selEntity as Arc;
                            Plane   myPlane    = (Plane)arc.Plane.Clone();
                            Point3D startPoint = arc.StartPoint;
                            Point3D endPoint   = arc.EndPoint;

                            // checks if the Arc is clockwise
                            if (Utility.IsOrientedClockwise(arc.Vertices))
                            {
                                myPlane.Flip();
                                startPoint = arc.EndPoint;
                                endPoint   = arc.StartPoint;
                            }

                            AngularDim angularDim = new AngularDim(myPlane, startPoint, endPoint, points[points.Count - 1], dimTextHeight);

                            angularDim.TextSuffix = "°";

                            AddAndRefresh(angularDim, ActiveLayerName);
                            drawingAngularDim = false;
                        }
                    }

                    // If it's not time to set quadrantPoint, adds the lines for angular dim
                    if (selEntity is Line && !drawingQuadrantPoint && quadrantPoint == null)
                    {
                        Line selectedLine = (Line)selEntity;

                        if (firstLine == null)
                        {
                            firstLine = selectedLine;
                        }
                        else if (secondLine == null && !ReferenceEquals(firstLine, selectedLine))
                        {
                            secondLine           = selectedLine;
                            drawingQuadrantPoint = true;
                            // resets points to get only the quadrant point and text position point
                            points.Clear();
                        }

                        drawingAngularDimFromLines = true;
                    }
                    else if (drawingQuadrantPoint)
                    {
                        ScreenToPlane(mousePos, plane, out quadrantPoint);
                        drawingQuadrantPoint = false;
                    }
                    //if all parameters are present, gets angular dim
                    else if (points.Count == 2 && quadrantPoint != null)
                    {
                        AngularDim angularDim = new AngularDim(plane, (Line)firstLine.Clone(), (Line)secondLine.Clone(), quadrantPoint, points[points.Count - 1], dimTextHeight);

                        angularDim.TextSuffix = "°";

                        AddAndRefresh(angularDim, ActiveLayerName);

                        drawingAngularDim          = false;
                        drawingAngularDimFromLines = false;
                    }
                }
                else if (doingOffset && points.Count == 1)
                {
                    CreateOffsetEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingMirror && points.Count == 2 && selEntity != null)
                {
                    CreateMirrorEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingExtend && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    ExtendEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingTrim && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    TrimEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingFillet && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateFilletEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingChamfer && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateChamferEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingTangents && firstSelectedEntity != null && secondSelectedEntity != null)
                {
                    CreateTangentEntity();
                    ClearAllPreviousCommandData();
                }
                else if (doingMove && points.Count == 2)
                {
                    if (points.Count == 2)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            Vector3D movement = new Vector3D(points[0], points[1]);
                            ent.Translate(movement);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
                else if (doingRotate)
                {
                    if (points.Count == 3)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            ent.Rotate(arcSpanAngle, Vector3D.AxisZ, points[0]);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
                else if (doingScale)
                {
                    if (points.Count == 3)
                    {
                        foreach (Entity ent in this.selEntities)
                        {
                            ent.Scale(points[0], scaleFactor);
                        }

                        Entities.Regen();
                        ClearAllPreviousCommandData();
                    }
                }
            }
            #endregion

            #region Handle RMB Clicks
            else if (e.ChangedButton == MouseButton.Right)
            {
                ScreenToPlane(mousePos, plane, out current);

                if (drawingPoints)
                {
                    points.Clear();
                    drawingPoints = false;
                }
                else if (drawingText)
                {
                    drawingText = false;
                }
                else if (drawingLeader)
                {
                    drawingLeader = false;
                }

                // If drawing polyline, create and add LinearPath entity to model
                else if (drawingPolyLine)
                {
                    LinearPath lp = new LinearPath(points);
                    AddAndRefresh(lp, ActiveLayerName);

                    drawingPolyLine = false;
                }
                // If drawing spline, create and add curve entity to model
                else if (drawingCurve)
                {
#if NURBS
                    Curve curve = Curve.CubicSplineInterpolation(points);
                    AddAndRefresh(curve, ActiveLayerName);
#endif
                    drawingCurve = false;
                }
                else
                {
                    ClearAllPreviousCommandData();
                }
            }
            #endregion

            base.OnMouseDown(e);
        }