AddPyramid() public method

Adds a pyramid.
See http://en.wikipedia.org/wiki/Pyramid_(geometry).
public AddPyramid ( System.Windows.Media.Media3D.Point3D center, double sideLength, double height ) : void
center System.Windows.Media.Media3D.Point3D /// The center. ///
sideLength double /// Length of the sides of the pyramid. ///
height double /// The height of the pyramid. ///
return void
Beispiel #1
0
        //private ht.TranslateManipulator translateModificator;

        /// <summary>
        /// The tessellate.
        /// </summary>
        /// <returns>The mesh.</returns>
        protected override MeshGeometry3D Tessellate()
        {
            var builder = new ht.MeshBuilder(true, true);

            // Position and Rotation must not be concidered because they are handled by the visual 3d
            if (this.Sensor == null)
            {
                builder.AddPyramid(new Point3D(), 1, 1);
                return(builder.ToMesh());
            }
            var _zeroPosition = new Point3D();// this.Transform.Value.GetTranslation() - this.Position;

            var _length = new Spherical3D(this.Sensor.MaxRange, 0, 0);

            var _dirSp = this.Orientation.Axis.ToSpherical();

            _dirSp.Radius = 0;

            var _p0AzOffset = new Spherical3D(0, 0, this.Sensor.AzimuthRange / 2.0);
            var _p0ElOffset = new Spherical3D(0, this.Sensor.ElevationRange / 2.0, 0);

            var _pts = new List <Point3D>();

            _pts.Add(_zeroPosition + this.Orientation.Axis + (_length + _p0ElOffset - _p0AzOffset + _dirSp).ToDirection());
            _pts.Add(_zeroPosition + this.Orientation.Axis + (_length + _p0ElOffset + _p0AzOffset + _dirSp).ToDirection());
            _pts.Add(_zeroPosition + this.Orientation.Axis + (_length - _p0ElOffset + _p0AzOffset + _dirSp).ToDirection());
            _pts.Add(_zeroPosition + this.Orientation.Axis + (_length - _p0ElOffset - _p0AzOffset + _dirSp).ToDirection());

            _pts.Sort((Point3D a, Point3D b) =>
            {
                if (Math.Abs(a.X - b.X) < DBL_EqualOffset)
                {
                    if (Math.Abs(a.Y - b.Y) < DBL_EqualOffset)
                    {
                        return(a.Z.CompareTo(b.Z));
                    }
                    return(a.Y.CompareTo(b.Y));
                }
                return(a.X.CompareTo(b.X));
            });

            // outside
            builder.AddTriangle(_pts[0], _zeroPosition, _pts[1]);
            builder.AddTriangle(_pts[3], _zeroPosition, _pts[2]);
            builder.AddTriangle(_pts[2], _zeroPosition, _pts[0]);
            builder.AddTriangle(_pts[1], _zeroPosition, _pts[3]);

            this.Material     = this.outsideMat;
            this.BackMaterial = this.insideMat;
            return(builder.ToMesh());
        }
        GeometryModel3D AddGeometry(IEnumerable<Point3D> centers, double l)
        {
            var builder = new MeshBuilder();

            foreach (var center in centers)
            {
                builder.AddPyramid(center, l, l, true);
            }

            var mv = new GeometryModel3D
                             {
                                 Geometry = builder.ToMesh(true),
                                 Material = MaterialHelper.CreateMaterial(Brushes.Gold)
                             };

            TriangleCount = builder.TriangleIndices.Count / 3;

            return mv;
        }
Beispiel #3
0
        /// <summary>
        /// Add a pyramid geometry object pointing up with base centred at (0,0,0).
        /// </summary>
        /// <param name="shapeName">The 3DView object.</param>
        /// <param name="sideLength">The radius of the base.</param>
        /// <param name="height">The height of the cone.</param>
        /// <param name="colour">A colour or gradient brush for the object.</param>
        /// <param name="materialType">A material for the object.
        /// The available options are:
        /// "E" Emmissive - constant brightness.
        /// "D" Diffusive - affected by lights.
        /// "S" Specular  - specular highlights.
        /// </param>
        /// <returns>The 3DView Geometry name.</returns>
        public static Primitive AddPyramid(Primitive shapeName, Primitive sideLength, Primitive height, Primitive colour, Primitive materialType)
        {
            UIElement obj;

            try
            {
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            if (obj.GetType() == typeof(Viewport3D))
                            {
                                MeshBuilder builder = new MeshBuilder(true, true);
                                builder.AddPyramid(new Point3D(0, 0, 0), sideLength, height);
                                MeshGeometry3D mesh = builder.ToMesh();

                                Viewport3D viewport3D = (Viewport3D)obj;
                                return AddGeometry(viewport3D, mesh.Positions, mesh.TriangleIndices, mesh.Normals, mesh.TextureCoordinates, colour, materialType);
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                        return "";
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }