예제 #1
0
        public static WW3DModel GenerateCuboid(Size3D wdh, Vector3D offset, NormalDirection nd)
        {
            var points = new List<Point3D>();
            points.Add(new Point3D(-wdh.X / 2 + offset.X, -wdh.Y / 2 + offset.Y, wdh.Z / 2 + offset.Z));
            points.Add(new Point3D(-wdh.X / 2 + offset.X, -wdh.Y / 2 + offset.Y, -wdh.Z / 2 + offset.Z));
            points.Add(new Point3D(wdh.X / 2 + offset.X, -wdh.Y / 2 + offset.Y, -wdh.Z / 2 + offset.Z));
            points.Add(new Point3D(wdh.X / 2 + offset.X, -wdh.Y / 2 + offset.Y, wdh.Z / 2 + offset.Z));

            points.Add(new Point3D(-wdh.X / 2 + offset.X, wdh.Y / 2 + offset.Y, wdh.Z / 2 + offset.Z));
            points.Add(new Point3D(-wdh.X / 2 + offset.X, wdh.Y / 2 + offset.Y, -wdh.Z / 2 + offset.Z));
            points.Add(new Point3D(wdh.X / 2 + offset.X, wdh.Y / 2 + offset.Y, -wdh.Z / 2 + offset.Z));
            points.Add(new Point3D(wdh.X / 2 + offset.X, wdh.Y / 2 + offset.Y, wdh.Z / 2 + offset.Z));

            int[] indices = null;

            switch (nd) {
            case NormalDirection.Outward:
                indices = new int[] {
                    5, 1, 0, 6, 2, 1, 7, 3, 2, 4, 0, 3,
                    1, 2, 3, 6, 5, 4, 4, 5, 0, 5, 6, 1,
                    6, 7, 2, 7, 4, 3, 0, 1, 3, 7, 6, 4 };
                break;
            case NormalDirection.Inward:
                indices = new int[] {
                    0,1,5,1,2,6,2,3,7,3,0,4,
                    3,2,1,4,5,6,0,5,4,1,6,5,
                    2,7,6,3,4,7,3,1,0,4,6,7};
                break;
            }

            return new WW3DModel(points.ToArray(), indices);
        }
        internal static MeshGeometry3D AddAgentGeometry(Point3D position, Size3D size, MeshGeometry3D mesh)
        {
            Point3D p1 = new Point3D(position.X + 0, position.Y + 0, position.Z + 0);
            Point3D p2 = new Point3D(position.X + size.X, position.Y + 0, position.Z + 0);
            Point3D p3 = new Point3D(position.X + size.X, position.Y + 0, position.Z + size.Z);
            Point3D p4 = new Point3D(position.X + 0, position.Y + 0, position.Z + size.Z);
            Point3D p5 = new Point3D(position.X + 0, position.Y + size.Y, position.Z + 0);
            Point3D p6 = new Point3D(position.X + size.X, position.Y + size.Y, position.Z + 0);
            Point3D p7 = new Point3D(position.X + size.X, position.Y + size.Y, position.Z + size.Z);
            Point3D p8 = new Point3D(position.X + 0, position.Y + size.Y, position.Z + size.Z);

            return CubeModel(p1, p2, p3, p4, p5, p6, p7, p8, mesh);
        }
 internal static ModelVisual3D GetModel(Point3D position, Size3D size, double angle)
 {
     Model3DGroup group = LoadModel();
     Transform3DGroup trgr = new Transform3DGroup();
     trgr.Children.Add(new ScaleTransform3D(size.X, size.Y, size.Z));
     trgr.Children.Add(new TranslateTransform3D(position.X, position.Y, position.Z));
     trgr.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 3, 0), angle)));
     group.Transform = trgr;
     return new ModelVisual3D()
     {
         Content = group
     };
 }
예제 #4
0
        // Displays the values of the variables
        public void ShowVars()
        {
            Point3D p1 = new Point3D(10, 5, 1);

            Vector3D v1 = new Vector3D(20, 30, 40);
            Size3D s1 = new Size3D(2, 4, 6);
            Size3D s2 = new Size3D(5, 10, 15);

            // Displaying values in Text objects
            txtPoint1.Text = p1.ToString();
            txtVector1.Text = v1.ToString();
            txtSize1.Text = s1.ToString();
            txtSize2.Text = s2.ToString();
        }
예제 #5
0
        /// <summary>
        /// Attempts to convert to a Size3D from the given object.
        /// </summary>
        /// <returns>
        /// The Size3D which was constructed.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// A NotSupportedException is thrown if the example object is null or is not a valid type
        /// which can be converted to a Size3D.
        /// </exception>
        /// <param name="context"> The ITypeDescriptorContext for this call. </param>
        /// <param name="culture"> The requested CultureInfo.  Note that conversion uses "en-US" rather than this parameter. </param>
        /// <param name="value"> The object to convert to an instance of Size3D. </param>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                throw GetConvertFromException(value);
            }

            String source = value as string;

            if (source != null)
            {
                return(Size3D.Parse(source));
            }

            return(base.ConvertFrom(context, culture, value));
        }
예제 #6
0
파일: Rect3D.cs 프로젝트: dox0/DotNet471RS3
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor which sets the initial values to the values of the parameters.
        /// </summary>
        /// <param name="location">Location of the new rectangle.</param>
        /// <param name="size">Size of the new rectangle.</param>
        public Rect3D(Point3D location, Size3D size)
        {
            if (size.IsEmpty)
            {
                this = s_empty;
            }
            else
            {
                _x     = location._x;
                _y     = location._y;
                _z     = location._z;
                _sizeX = size._x;
                _sizeY = size._y;
                _sizeZ = size._z;
            }
            Debug.Assert(size.IsEmpty == IsEmpty);
        }
예제 #7
0
파일: Rect3D.cs 프로젝트: JianwenSun/cc
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor which sets the initial values to the values of the parameters.
        /// </summary>
        /// <param name="location">Location of the new rectangle.</param>
        /// <param name="size">Size of the new rectangle.</param>
        public Rect3D(Point3D location, Size3D size)
        {
            if (size.IsEmpty)
            {
                this = s_empty;
            }
            else
            {
                _x = location._x;
                _y = location._y;
                _z = location._z;
                _sizeX = size._x;
                _sizeY = size._y;
                _sizeZ = size._z;
            }
            Debug.Assert(size.IsEmpty == IsEmpty);
        }
예제 #8
0
        /// <summary>
        /// ConvertTo - Attempt to convert an instance of Size3D to the given type
        /// </summary>
        /// <returns>
        /// The object which was constructoed.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// A NotSupportedException is thrown if "value" is null or not an instance of Size3D,
        /// or if the destinationType isn't one of the valid destination types.
        /// </exception>
        /// <param name="context"> The ITypeDescriptorContext for this call. </param>
        /// <param name="culture"> The CultureInfo which is respected when converting. </param>
        /// <param name="value"> The object to convert to an instance of "destinationType". </param>
        /// <param name="destinationType"> The type to which this will convert the Size3D instance. </param>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != null && value is Size3D)
            {
                Size3D instance = (Size3D)value;

                if (destinationType == typeof(string))
                {
                    // Delegate to the formatting/culture-aware ConvertToString method.

                    #pragma warning suppress 6506 // instance is obviously not null
                    return(instance.ConvertToString(null, culture));
                }
            }

            // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.)
            return(base.ConvertTo(context, culture, value, destinationType));
        }
예제 #9
0
 public override void Initialize(Dictionary<string, object> settings)
 {
     Random rand = new Random();
     if (rand.NextDouble() > 0.5)
     {
         Size = new Size3D(8, 2.2, 2.2);
         base.MaxCapasity = 82;
         base.CurrentAgentCount = rand.Next(82);
     }
     else
     {
         Size = new Size3D(4.5, 1.82, 1.5);
         base.MaxCapasity = 20;
         base.CurrentAgentCount = rand.Next(20);
     }
     _maxSpeed = 360 + (rand.NextDouble() - 0.7) * 100;
     InputFactor = 25;
     OutputFactor = 25;
     _acceleration = 0.2;
     _deceleration = 0.4;
 }
예제 #10
0
 public BindableSize3DModel(Size3D size)
 {
     _size = new Size3D(size.X, size.Y, size.Z);
 }
예제 #11
0
 public BindableSize3DModel(Rect3D size)
 {
     _size = size.IsEmpty ? new Size3D() : new Size3D(size.SizeX, size.SizeY, size.SizeZ);
 }
예제 #12
0
 public BindableSize3DModel(int width, int height, int depth)
 {
     _size = new Size3D(width, height, depth);
 }
예제 #13
0
 public BindableSize3DModel()
 {
     _size = new Size3D(0, 0, 0);
 }
예제 #14
0
        /// <summary> 
        /// Parse - returns an instance converted from the provided string using
        /// the culture "en-US" 
        /// <param name="source"> string with Size3D data </param>
        /// </summary>
        public static Size3D Parse(string source)
        { 
            IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;
 
            TokenizerHelper th = new TokenizerHelper(source, formatProvider); 

            Size3D value; 

            String firstToken = th.NextTokenRequired();

            // The token will already have had whitespace trimmed so we can do a 
            // simple string compare.
            if (firstToken == "Empty") 
            { 
                value = Empty;
            } 
            else
            {
                value = new Size3D(
                    Convert.ToDouble(firstToken, formatProvider), 
                    Convert.ToDouble(th.NextTokenRequired(), formatProvider),
                    Convert.ToDouble(th.NextTokenRequired(), formatProvider)); 
            } 

            // There should be no more tokens in this string. 
            th.LastTokenRequired();

            return value;
        } 
        internal static MeshGeometry3D AddAgentGeometry(System.Windows.Media.Media3D.Point3D position, System.Windows.Media.Media3D.Size3D size, System.Windows.Media.Media3D.MeshGeometry3D mesh)
        {
            Point3D p1 = new Point3D(position.X + 0, position.Y + 0, position.Z + 0);
            Point3D p2 = new Point3D(position.X + size.X, position.Y + 0, position.Z + 0);
            Point3D p3 = new Point3D(position.X + size.X, position.Y + 0, position.Z + size.Z);
            Point3D p4 = new Point3D(position.X + 0, position.Y + 0, position.Z + size.Z);
            Point3D p5 = new Point3D(position.X + 0, position.Y + size.Y, position.Z + 0);
            Point3D p6 = new Point3D(position.X + size.X, position.Y + size.Y, position.Z + 0);
            Point3D p7 = new Point3D(position.X + size.X, position.Y + size.Y, position.Z + size.Z);
            Point3D p8 = new Point3D(position.X + 0, position.Y + size.Y, position.Z + size.Z);

            return(CubeModel(p1, p2, p3, p4, p5, p6, p7, p8, mesh));
        }
예제 #16
0
 private static Size3D CreateEmptySize3D()
 {
     Size3D empty = new Size3D();
     // Can't use setters because they throw on negative values
     empty._x = Double.NegativeInfinity;
     empty._y = Double.NegativeInfinity;
     empty._z = Double.NegativeInfinity;
     return empty;
 }
예제 #17
0
파일: FlipTile.cs 프로젝트: hungdluit/bot
        private static Model3DGroup CreateTile(Material frontMaterial, Material backMaterial, Material sideMaterial,
            Size3D size, Rect backMaterialCoordiantes)
        {
            //these are represent half the width, height, depth of the quads, since everything is from zero
            double w = size.X / 2;
            double h = size.Y / 2;
            double d = size.Z / 2;

            //front
            GeometryModel3D front = GetQuad(
                new Point3D(-w, -h, d),
                new Point3D(w, -h, d),
                new Point3D(w, h, d),
                new Point3D(-w, h, d),
                frontMaterial);

            //back
            GeometryModel3D back = GetQuad(
                new Point3D(-w, -h, d),
                new Point3D(w, -h, d),
                new Point3D(w, h, d),
                new Point3D(-w, h, d),
                backMaterial, backMaterialCoordiantes);

            RotateTransform3D backRotate =
                new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180), new Point3D());
            RotateTransform3D backFlip =
                new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180), new Point3D());

            Transform3DGroup backTransformGroup = new Transform3DGroup();
            backTransformGroup.Children.Add(backRotate);
            backTransformGroup.Children.Add(backFlip);

            back.Transform = backTransformGroup;

            GeometryModel3D bottom, left, top, right;
            //sides
            {
                //right
                right = GetQuad(
                    new Point3D(w, -h, d),
                    new Point3D(w, -h, -d),
                    new Point3D(w, h, -d),
                    new Point3D(w, h, d), sideMaterial);

                //left
                left = GetQuad(
                    new Point3D(-w, -h, -d),
                    new Point3D(-w, -h, d),
                    new Point3D(-w, h, d),
                    new Point3D(-w, h, -d), sideMaterial);

                //top
                top = GetQuad(
                    new Point3D(-w, h, d),
                    new Point3D(w, h, d),
                    new Point3D(w, h, -d),
                    new Point3D(-w, h, -d), sideMaterial);

                //bottom
                bottom = GetQuad(
                    new Point3D(-w, -h, -d),
                    new Point3D(w, -h, -d),
                    new Point3D(w, -h, d),
                    new Point3D(-w, -h, d), sideMaterial);
            }

            Model3DGroup group = new Model3DGroup();
            group.Children.Add(front);
            group.Children.Add(back);
            group.Children.Add(right);
            group.Children.Add(left);
            group.Children.Add(bottom);
            group.Children.Add(top);

            return group;
        }
 public Rect3D(Point3D location, Size3D size)
 {
 }
예제 #19
0
파일: Size3D.cs 프로젝트: z2516305651/wpf
 /// <summary>
 /// Equals - compares this Size3D with the passed in object.  In this equality
 /// Double.NaN is equal to itself, unlike in numeric equality.
 /// Note that double values can acquire error when operated upon, such that
 /// an exact comparison between two values which
 /// are logically equal may fail.
 /// </summary>
 /// <returns>
 /// bool - true if "value" is equal to "this".
 /// </returns>
 /// <param name='value'>The Size3D to compare to "this"</param>
 public bool Equals(Size3D value)
 {
     return(Size3D.Equals(this, value));
 }
예제 #20
0
 /// <summary> 
 /// Compares two Size3D instances for object equality.  In this equality
 /// Double.NaN is equal to itself, unlike in numeric equality. 
 /// Note that double values can acquire error when operated upon, such that 
 /// an exact comparison between two values which
 /// are logically equal may fail. 
 /// </summary>
 /// <returns>
 /// bool - true if the two Size3D instances are exactly equal, false otherwise
 /// </returns> 
 /// <param name='size1'>The first Size3D to compare</param>
 /// <param name='size2'>The second Size3D to compare</param> 
 public static bool Equals (Size3D size1, Size3D size2) 
 {
     if (size1.IsEmpty) 
     {
         return size2.IsEmpty;
     }
     else 
     {
         return size1.X.Equals(size2.X) && 
                size1.Y.Equals(size2.Y) && 
                size1.Z.Equals(size2.Z);
     } 
 }
예제 #21
0
        public override void UpdateGeneralFromEntityBase()
        {
            double scaleMultiplyer = CubeGrid.GridSizeEnum.ToLength();
            if (IsStatic && CubeGrid.GridSizeEnum == MyCubeSize.Large)
            {
                ClassType = ClassType.Station;
            }
            else if (!IsStatic && CubeGrid.GridSizeEnum == MyCubeSize.Large)
            {
                ClassType = ClassType.LargeShip;
            }
            else if (!IsStatic && CubeGrid.GridSizeEnum == MyCubeSize.Small)
            {
                ClassType = ClassType.SmallShip;
            }

            var min = new Point3D(int.MaxValue, int.MaxValue, int.MaxValue);
            var max = new Point3D(int.MinValue, int.MinValue, int.MinValue);
            float totalMass = 0;

            foreach (var block in CubeGrid.CubeBlocks)
            {
                min.X = Math.Min(min.X, block.Min.X);
                min.Y = Math.Min(min.Y, block.Min.Y);
                min.Z = Math.Min(min.Z, block.Min.Z);

                var cubeDefinition = SpaceEngineersApi.GetCubeDefinition(block.TypeId, CubeGrid.GridSizeEnum, block.SubtypeName);

                // definition is null when the block no longer exists in the Cube definitions. Ie, Ladder, or a Mod that was removed.
                if (cubeDefinition == null || (cubeDefinition.Size.X == 1 && cubeDefinition.Size.Y == 1 && cubeDefinition.Size.z == 1))
                {
                    max.X = Math.Max(max.X, block.Min.X);
                    max.Y = Math.Max(max.Y, block.Min.Y);
                    max.Z = Math.Max(max.Z, block.Min.Z);
                }
                else
                {
                    // resolve the cube size acording to the cube's orientation.
                    var orientSize = cubeDefinition.Size.Add(-1).Transform(block.BlockOrientation).Abs();
                    max.X = Math.Max(max.X, block.Min.X + orientSize.X);
                    max.Y = Math.Max(max.Y, block.Min.Y + orientSize.Y);
                    max.Z = Math.Max(max.Z, block.Min.Z + orientSize.Z);
                }

                var cubeBlockDefinition = SpaceEngineersApi.GetCubeDefinition(block.TypeId, CubeGrid.GridSizeEnum, block.SubtypeName);

                float cubeMass = 0;
                if (cubeBlockDefinition != null)
                {
                    foreach (var component in cubeBlockDefinition.Components)
                    {
                        var cd = (MyObjectBuilder_ComponentDefinition)SpaceEngineersApi.GetDefinition(component.Type, component.Subtype);
                        float componentMass = cd.Mass * component.Count;
                        cubeMass += componentMass;
                    }
                }

                totalMass += cubeMass;
            }

            var cockpitOrientation = "None";
            var cockpits = CubeGrid.CubeBlocks.Where(b => b is MyObjectBuilder_Cockpit).ToArray();
            if (cockpits.Length > 0)
            {
                var count = cockpits.Count(b => b.BlockOrientation.Forward == cockpits[0].BlockOrientation.Forward && b.BlockOrientation.Up == cockpits[0].BlockOrientation.Up);
                if (cockpits.Length == count)
                {
                    // All cockpits share the same orientation.
                    cockpitOrientation = string.Format("Forward={0} ({1}), Up={2} ({3})", cockpits[0].BlockOrientation.Forward, GetAxisIndicator(cockpits[0].BlockOrientation.Forward), cockpits[0].BlockOrientation.Up, GetAxisIndicator(cockpits[0].BlockOrientation.Up));
                }
                else
                {
                    // multiple cockpits are present, and do not share a common orientation.
                    cockpitOrientation = "Mixed";
                }
            }
            CockpitOrientation = cockpitOrientation;

            var scale = max - min;
            scale.X++;
            scale.Y++;
            scale.Z++;

            if (CubeGrid.CubeBlocks.Count == 0)
                scale = new System.Windows.Media.Media3D.Vector3D();

            Min = min;
            Max = max;
            Scale = scale;
            Size = new Size3D(scale.X * scaleMultiplyer, scale.Y * scaleMultiplyer, scale.Z * scaleMultiplyer);
            Mass = totalMass;

            var quaternion = CubeGrid.PositionAndOrientation.Value.ToQuaternionD();
            var p1 = (min.ToVector3D() * CubeGrid.GridSizeEnum.ToLength()).Transform(quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
            var p2 = ((min.ToVector3D() + Scale.ToVector3D()) * CubeGrid.GridSizeEnum.ToLength()).Transform(quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
            //var p1 = VRageMath.Vector3D.Transform(min.ToVector3D() * CubeGrid.GridSizeEnum.ToLength(), quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
            //var p2 = VRageMath.Vector3D.Transform((min.ToVector3D() + Scale.ToVector3D()) * CubeGrid.GridSizeEnum.ToLength(), quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
            WorldAABB = new BoundingBoxD(VRageMath.Vector3D.Min(p1, p2), VRageMath.Vector3D.Max(p1, p2));
            Center = WorldAABB.Center;

            DisplayName = CubeGrid.DisplayName;

            // Add Beacon or Antenna detail for the Description.
            var broadcasters = CubeGrid.CubeBlocks.Where(b => b.SubtypeName == SubtypeId.LargeBlockBeacon.ToString()
                || b.SubtypeName == SubtypeId.SmallBlockBeacon.ToString()
                || b.SubtypeName == SubtypeId.LargeBlockRadioAntenna.ToString()
                || b.SubtypeName == SubtypeId.SmallBlockRadioAntenna.ToString()).ToArray();
            var broadcastNames = string.Empty;
            if (broadcasters.Length > 0)
            {
                var beaconNames = broadcasters.Where(b => b is MyObjectBuilder_Beacon).Select(b => ((MyObjectBuilder_Beacon)b).CustomName ?? "Beacon").ToArray();
                var antennaNames = broadcasters.Where(b => b is MyObjectBuilder_RadioAntenna).Select(b => ((MyObjectBuilder_RadioAntenna)b).CustomName ?? "Antenna").ToArray();
                broadcastNames = String.Join("|", beaconNames.Concat(antennaNames).OrderBy(s => s));
            }

            if (string.IsNullOrEmpty(broadcastNames))
                Description = string.Format("{0}×{1}×{2}", Scale.X, Scale.Y, Scale.Z, broadcastNames);
            else
                Description = string.Format("{3} {0}×{1}×{2}", Scale.X, Scale.Y, Scale.Z, broadcastNames);


            // TODO:
            // Report:
            // Reflectors On
            // Mass:      9,999,999 Kg
            // Speed:          0.0 m/s
            // Power Usage:      0.05%
            // Reactors:     12,999 GW
            // Thrusts:            999
            // Gyros:              999
            // Fuel Time:        0 sec
        }
 public Rect3D(Point3D location, Size3D size)
 {
 }
예제 #23
0
        private void PerformOperation(object sender, RoutedEventArgs e)
        {
            RadioButton li = (sender as RadioButton);

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li.Name)
            {   //begin switch

                case "rb1":
                    {
                        // Checks if two Size3D structures are equal using the static Equals method.
                        // Returns a Boolean.

                        // Declaring Size3D structure without initializing x,y,z values
                        Size3D size1 = new Size3D();

                        // Declaring Size3D structure and initializing x,y,z values
                        Size3D size2 = new Size3D(5, 10, 15);
                        Boolean areEqual;

                        // Assigning values to size1
                        size1.X = 2;
                        size1.Y = 4;
                        size1.Z = 6;

                        // checking for equality
                        areEqual = Size3D.Equals(size1, size2);

                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = Size3D.Equals(size1, size2);";
                        resultType = "Boolean";
                        operationString = "Checking if two Size3D structures are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb2":
                    {
                        // Checks if an Object and a Size3D structure are equal using the non-static Equals method.
                        // Returns a Boolean.

                        // Declaring Size3D structure without initializing x,y,z values
                        Size3D size1 = new Size3D();

                        // Declaring Size3D structure and initializing x,y,z values
                        Size3D size2 = new Size3D(5, 10, 15);
                        Boolean areEqual;

                        // Assigning values to size1
                        size1.X = 2;
                        size1.Y = 4;
                        size1.Z = 6;

                        areEqual = size1.Equals(size2);
                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = Size3D.Equals(size1, size2);";
                        resultType = "Boolean";
                        operationString = "Checking if an object and a Size3D structure are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Checks if two Size3D structures are equal using the overloaded == operator.
                        // Returns a Boolean.

                        // Declaring Size3D structure without initializing x,y,z values
                        Size3D size1 = new Size3D();

                        // Declaring Size3D structure and initializing x,y,z values
                        Size3D size2 = new Size3D(5, 10, 15);
                        Boolean areEqual;

                        // Assigning values to size1
                        size1.X = 2;
                        size1.Y = 4;
                        size1.Z = 6;

                        // Checking for equality
                        areEqual = size1 == size2;

                        // areEqual is False

                        // Displaying Results
                        syntaxString = " areEqual = size1 == size2;";
                        resultType = "Boolean";
                        operationString = "Checking if two Size3D structures are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Checks if two Size3D structures are not equal using the overloaded != operator.
                        // Returns a Boolean.

                        Size3D size1 = new Size3D(2, 4, 6);
                        Size3D size2 = new Size3D(5, 10, 15);
                        Boolean areNotEqual;

                        areNotEqual = size1 != size2;
                        // areNotEqual is True

                        // Displaying Results
                        syntaxString = "areNotEqual = size1 != size2;";
                        resultType = "Boolean";
                        operationString = "Checking if two Size3D structures are not equal";
                        ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Converts a string representation of a 3-D size into a Size3D structure.

                        Size3D sizeResult = new Size3D();

                        sizeResult = Size3D.Parse("10,20,30");
                        // sizeResult is equal to (10,20,30)

                        // Displaying Results
                        syntaxString = "sizeResult = Size3D.Parse(\"10,20,30\");";
                        resultType = "Size3D";
                        operationString = "Converting a string into a Size3D structure";
                        ShowResults(sizeResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Explicitly converts a Size3D structure into a Vector3D structure
                        // Returns a Vector3D.

                        Size3D size1 = new Size3D(2, 4, 6);
                        Vector3D vector1 = new Vector3D();

                        vector1 = (Vector3D)size1;
                        // vector1 is equal to (2, 4, 6)

                        // Displaying Results
                        syntaxString = "vector1 = (Vector3D)size1;";
                        resultType = "Vector3D";
                        operationString = "Expliciting casting a Size3D into a Vector3D";
                        ShowResults(vector1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb7":
                    {
                        // Explicitly converts a Size3D structure into a Point3D structure
                        // Returns a Vector3D.

                        Size3D size1 = new Size3D(2, 4, 6);
                        Point3D point1 = new Point3D();

                        point1 = (Point3D)size1;
                        // point1 is equal to (2, 4, 6)

                        // Displaying Results
                        syntaxString = "point1 = (Point3D)size1;";
                        resultType = "Point3D";
                        operationString = "Expliciting casting a Size3D into a Point3D";
                        ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb8":
                    {
                        // Checks if a Size3D structure is empty
                        // Returns Boolean

                        Size3D size1 = new Size3D(0, 0, 0);
                        Boolean isEmpty;

                        isEmpty = size1.IsEmpty;
                        // isEmpty is False

                        // Displaying Results
                        syntaxString = "isEmpty = size1.IsEmpty;";
                        resultType = "Boolean";
                        operationString = "Checking if a Size3D structure is empty";
                        ShowResults(isEmpty.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb9":
                    {
                        // Gets an empty Size3D structure
                        Size3D size1 = new Size3D(2, 4, 6);

                        size1 = Size3D.Empty;
                        // size1 is now empty

                        // Displaying Results
                        syntaxString = "size1 = Size3D.Empty;";
                        resultType = "Size3D";
                        operationString = "Getting an empty Size3D structure";
                        ShowResults(size1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb10":
                    {
                        // Gets a string representation of a Size3D Structure

                        Size3D size1 = new Size3D(2,4,6);
                        String sizeString;

                        sizeString = size1.ToString();
                        // sizeString is equal to "2,4,6"

                        // Displaying Results
                        resultType = "String";
                        syntaxString = "sizeString = size1.ToString();";
                        operationString = "Getting the ToString of size1";
                        ShowResults(sizeString.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb11":
                    {
                        // Gets the hashcode of a Size3D Structure

                        Size3D size1 = new Size3D(2, 4, 6);
                        int sizeHashcode;

                        sizeHashcode = size1.GetHashCode();

                        // Displaying Results
                        resultType = "int";
                        syntaxString = "sizeHashcode = size1.GetHashCode;";
                        operationString = "Getting the hashcode of size1";
                        ShowResults(sizeHashcode.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                default:
                    break;

            } //end switch
        }
		protected void DrawLine(Point3D point)
		{
			// point was in cube [0..1]x[0..1]x[0..1], we are transforming it 
			// to cube [0..width]x[0..height]x[0..depth]

			Point3D start = point.TransformToBounds(bounds);

			int maxLength = 10 * Math.Max(width, Math.Max(height, depth));
			const int maxIterations = 400;
			Size3D boundsSize = new Size3D(1.0 / width, 1.0 / height, 1.0 / depth);

			Action<double, List<Point3D>> pointTracking = (direction, track) =>
			{
				var position01 = point;
				double length = 0;
				int i = 0;
				do
				{
					var K1 = fieldWrapper.GetVector(position01).DecreaseLength(boundsSize);
					var K2 = fieldWrapper.GetVector(position01 + (K1 / 2)).DecreaseLength(boundsSize);
					var K3 = fieldWrapper.GetVector(position01 + (K2 / 2)).DecreaseLength(boundsSize);
					var K4 = fieldWrapper.GetVector(position01 + K3).DecreaseLength(boundsSize);

					var shift = ((K1 + 2 * K2 + 2 * K3 + K4) / 6);
					if (shift.X.IsNaN() || shift.Y.IsNaN() || shift.Z.IsNaN())
						break;

					var next = position01 + direction * shift;
					Point3D viewportPoint = position01.TransformToBounds(bounds);
					track.Add(viewportPoint);

					position01 = next;
					length += shift.Length;
					i++;
				} while (length < maxLength && i < maxIterations);
			};

			var forwardTrack = new List<Point3D>();
			forwardTrack.Add(start);
			pointTracking(+1, forwardTrack);
			if (forwardTrack.Count > 1)
			{
				var forwardLine = CreatePolyline(forwardTrack, start);
				Children.Add(forwardLine);
			}

			var backwardTrack = new List<Point3D>();
			backwardTrack.Add(start);
			pointTracking(-1, backwardTrack);
			if (backwardTrack.Count > 1)
			{
				var backwardLine = CreatePolyline(backwardTrack, start);
				Children.Add(backwardLine);
			}
		}
예제 #25
0
		public static Vector3D DecreaseLength(this Vector3D vector, Size3D size)
		{
			return vector.DecreaseLength(size.X, size.Y, size.Z);
		}
예제 #26
0
 /// <summary> 
 /// Equals - compares this Size3D with the passed in object.  In this equality
 /// Double.NaN is equal to itself, unlike in numeric equality. 
 /// Note that double values can acquire error when operated upon, such that
 /// an exact comparison between two values which
 /// are logically equal may fail.
 /// </summary> 
 /// <returns>
 /// bool - true if "value" is equal to "this". 
 /// </returns> 
 /// <param name='value'>The Size3D to compare to "this"</param>
 public bool Equals(Size3D value) 
 {
     return Size3D.Equals(this, value);
 }
예제 #27
0
        // This method performs the Point operations
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            RadioButton li = (sender as RadioButton);

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
              switch (li.Name)
            {   //begin switch

                case "rb1":
                    {
                        // Converts a String to a Point using a PointConverter
                        // Returns a Point.

                        PointConverter pConverter = new PointConverter();
                        Point pointResult = new Point();
                        string string1 = "10,20";

                        pointResult = (Point)pConverter.ConvertFromString(string1);
                        // pointResult is equal to (10, 20)

                        // Displaying Results
                        syntaxString = "pointResult = (Point)pConverter1.ConvertFromString(string1);";
                        resultType = "Point";
                        operationString = "Converting a String to a Point";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb2":
                    {
                        // Converts a String to a Vector using a VectorConverter
                        // Returns a Vector.

                        VectorConverter vConverter = new VectorConverter();
                        Vector vectorResult = new Vector();
                        string string1 = "10,20";

                        vectorResult = (Vector)vConverter.ConvertFromString(string1);
                        // vectorResult is equal to (10, 20)

                        // Displaying Results
                        syntaxString = "vectorResult = (Vector)vConverter.ConvertFromString(string1);";
                        resultType = "Vector";
                        operationString = "Converting a String into a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Converts a String to a Matrix using a MatrixConverter
                        // Returns a Matrix.

                        MatrixConverter mConverter = new MatrixConverter();
                        Matrix matrixResult = new Matrix();
                        string string2 = "10,20,30,40,50,60";

                        matrixResult = (Matrix)mConverter.ConvertFromString(string2);
                        // matrixResult is equal to (10, 20, 30, 40, 50, 60)

                        // Displaying Results
                        syntaxString = "matrixResult = (Vector)mConverter.ConvertFromString(string2);";
                        resultType = "Matrix";
                        operationString = "Converting a String into a Matrix";
                        ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Converts a String to a Point3D using a Point3DConverter
                        // Returns a Point3D.

                        Point3DConverter p3DConverter = new Point3DConverter();
                        Point3D point3DResult = new Point3D();
                        string string3 = "10,20,30";

                        point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);
                        // point3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);";
                        resultType = "Point3D";
                        operationString = "Converting a String into a Point3D";
                        ShowResults(point3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Converts a String to a Vector3D using a Vector3DConverter
                        // Returns a Vector3D.

                        Vector3DConverter v3DConverter = new Vector3DConverter();
                        Vector3D vector3DResult = new Vector3D();
                        string string3 = "10,20,30";

                        vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);
                        // vector3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Vector3D";
                        operationString = "Converting a String into a Vector3D";
                        ShowResults(vector3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Converts a String to a Size3D using a Size3DConverter
                        // Returns a Size3D.

                        Size3DConverter s3DConverter = new Size3DConverter();
                        Size3D size3DResult = new Size3D();
                        string string3 = "10,20,30";

                        size3DResult = (Size3D)s3DConverter.ConvertFromString(string3);
                        // size3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "size3DResult = (Size3D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Size3D";
                        operationString = "Converting a String into a Size3D";
                        ShowResults(size3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb7":
                    {
                        // Converts a String to a Point4D using a Point4DConverter
                        // Returns a Point4D.

                        Point4DConverter p4DConverter = new Point4DConverter();
                        Point4D point4DResult = new Point4D();
                        string string4 = "10,20,30,40";

                        point4DResult = (Point4D)p4DConverter.ConvertFromString(string4);
                        // point4DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "point4DResult = (Point4D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Point4D";
                        operationString = "Converting a String into a Point4D";
                        ShowResults(point4DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                    default:
                    break;

            } //end switch
        }
예제 #28
0
 public override void Initialize(Dictionary<string, object> settings)
 {
     Random rand = new Random();
     var size = Enviroment.Constants.CELL_SIZE * (0.75 + rand.NextDouble() / 4.0);
     Size = new Size3D(size, size, size * 4.3);
     _maxSpeed = 360 + (rand.NextDouble() - 0.7) * 100;
     _acceleration = 0;
     _deceleration = 0;
     _direction = null;
 }