Exemple #1
0
        /// <summary>
        /// contructs a point with respect to another point and offset in x,y,z directions
        /// </summary>
        /// <param name="referencePoint">the point with respect to which the new point is contructed</param>
        /// <param name="deltaX">offset in the x direction</param>
        /// <param name="deltaY">offset in the y direction</param>
        /// <param name="deltaZ">offset in the z direction</param>
        /// <returns></returns>
        public static DSPoint ByOffset(DSPoint referencePoint, double deltaX, double deltaY, double deltaZ)
        {
            DSPoint newPnt = new DSPoint(referencePoint, deltaX, deltaY, deltaZ, true);

            newPnt.ReferencePoint = referencePoint;
            return(newPnt);
        }
Exemple #2
0
        protected override DSGeometry GetGeometryCore(out bool autodispose)
        {
            DSPoint p = VertexEntity.GetPointGeometry().ToPoint(false, null);

            autodispose = true;
            return(p);
        }
Exemple #3
0
        private static IConeEntity ByStartPointEndPointRadiusCore(DSPoint startPoint, DSPoint endPoint, double startRadius, double endRadius)
        {
            if (startRadius.LessThanOrEqualTo(0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "start radius"), "startRadius");
            }
            if (endRadius < 0.0)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "end radius"), "endRadius");
            }
            if (null == startPoint)
            {
                throw new System.ArgumentNullException("startPoint");
            }
            if (null == endPoint)
            {
                throw new System.ArgumentNullException("endPoint");
            }
            if (startPoint.DistanceTo(endPoint).EqualsTo(0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroDistance, "start point", "end point"), "startPoint, endPoint");
            }

            IConeEntity entity = HostFactory.Factory.ConeByPointsRadius(startPoint.PointEntity, endPoint.PointEntity, startRadius, endRadius);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCone.ByStartPointEndPointRadius"));
            }
            return(entity);
        }
Exemple #4
0
        private static IArcEntity ByCenterPointStartPointSweepPointCore(DSPoint centerPoint, DSPoint startPoint, DSPoint sweepPoint)
        {
            if (centerPoint == null)
            {
                throw new ArgumentNullException("centerPoint");
            }
            else if (startPoint == null)
            {
                throw new ArgumentNullException("startPoint");
            }
            else if (sweepPoint == null)
            {
                throw new ArgumentNullException("sweepPoint");
            }
            else if (startPoint.Equals(sweepPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "start point", "sweep point"), "startPoint, sweepPoint");
            }
            else if (startPoint.Equals(centerPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "start point", "center point"), "startPoint, centerPoint");
            }

            var arcEntity = HostFactory.Factory.ArcByCenterPointStartPointSweepPoint(centerPoint.PointEntity, startPoint.PointEntity, sweepPoint.PointEntity);

            if (null == arcEntity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSArc.ByCenterPointStartPointSweepPoint"));
            }
            return(arcEntity);
        }
Exemple #5
0
        /// <summary>
        /// Constructs a point by projecting a point on surface with given
        /// project direction.
        /// </summary>
        /// <param name="contextSurface">The surface on which the projection is to be made.</param>
        /// <param name="direction">The direction vector of the projection</param>
        /// <returns>Projected point on surface</returns>
        public DSPoint Project(DSSurface contextSurface, DSVector direction)
        {
            if (null == contextSurface)
            {
                throw new ArgumentNullException("contextSurface");
            }
            if (null == direction || direction.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, direction, "Project on surface"), "direction");
            }

            DSPoint pt = ProjectOnGeometry(contextSurface, direction);

            pt.Context        = contextSurface;
            pt.Direction      = direction;
            pt.ReferencePoint = this;
            double[] parameters = contextSurface.ParameterAtPoint(pt);
            if (null != parameters)
            {
                pt.U = parameters[0];
                pt.V = parameters[1];
            }

            return(pt);
        }
Exemple #6
0
 protected DSCircle(DSPoint firstPoint, DSPoint secondPoint, DSVector normal,bool persist)
     : base(By2PointsCore(firstPoint, secondPoint, ref normal),persist)
 {
     InitializeGuaranteedProperties();
     FirstPoint = firstPoint;
     SecondPoint = secondPoint;
 }
Exemple #7
0
        private static ICircleEntity ByCenterPointRadiusCore(DSPoint centerPoint, double radius, ref DSVector normal)
        {
            if (null == centerPoint)
            {
                throw new ArgumentNullException("centerPoint");
            }
            if (null == normal)
            {
                throw new ArgumentNullException("normal");
            }
            if (normal.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, "normal"), "normal");
            }
            if (radius <= 0.0)
            {
                throw new ArgumentException(Properties.Resources.IsZeroRadius);
            }

            normal = normal.IsNormalized ? normal : normal.Normalize();
            ICircleEntity entity = HostFactory.Factory.CircleByCenterPointRadius(centerPoint.PointEntity, radius, normal.IVector);

            if (null == entity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSCircle.ByCenterPointRadius"));
            }
            return(entity);
        }
 protected internal DSSubDivisionMesh(DSPoint[] vertices, int[][] faceIndices, int subDivisionLevel,bool persist)
     : base(ByVerticesFaceIndicesCore(vertices, faceIndices, subDivisionLevel),persist)
 {
     InitializeGuaranteedProperties();
     SubDivisionLevel = subDivisionLevel;
     Vertices = vertices;
 }
Exemple #9
0
        private static ISolidEntity RevolveCore(DSCurve profile, DSPoint axisOrigin, DSVector axisDirection, double startAngle, double sweepAngle)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            if (axisOrigin == null)
            {
                throw new ArgumentNullException("axisOrigin");
            }
            if (axisDirection == null)
            {
                throw new ArgumentNullException("axisDirection");
            }
            if (!profile.IsPlanar)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "profile"), "profile");
            }
            if (DSGeometryExtension.Equals(axisDirection.Length, 0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "axisDirection"), "axisDirection");
            }
            if (DSGeometryExtension.Equals(sweepAngle, 0.0))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "sweepAngle"), "sweepAngle");
            }

            ISolidEntity entity = HostFactory.Factory.SolidByRevolve(profile.CurveEntity, axisOrigin.PointEntity, axisDirection.IVector, startAngle, sweepAngle);

            if (entity == null)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSSolid.Revolve"));
            }
            return(entity);
        }
Exemple #10
0
 protected DSCircle(DSPoint firstPoint, DSPoint secondPoint, DSVector normal, bool persist)
     : base(By2PointsCore(firstPoint, secondPoint, ref normal), persist)
 {
     InitializeGuaranteedProperties();
     FirstPoint  = firstPoint;
     SecondPoint = secondPoint;
 }
Exemple #11
0
        private static ILineEntity ByStartPointDirectionLengthCore(DSPoint startPt, DSVector direction, double length)
        {
            if (startPt == null)
            {
                throw new ArgumentNullException("startPt");
            }
            else if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }
            else if (direction.IsZeroVector() || length == 0.0)
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, "direction"));
            }
            else if (length == 0.0)
            {
                throw new ArgumentException(Properties.Resources.IsZeroLength);
            }
            //Temporary end point is created by translating, should be disposed
            DSVector    offset = direction.Normalize().MultiplyBy(length);
            var         endPt  = startPt.Translate(offset, false);
            ILineEntity entity = HostFactory.Factory.LineByStartPointEndPoint(startPt.PointEntity, endPt.PointEntity);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSLine.ByStartPointDirectionLength"));
            }

            return(entity);
        }
Exemple #12
0
        private static IArcEntity ByCenterPointRadiusAngleCore(DSPoint centerPoint, double radius, double startAngle, double sweepAngle, ref DSVector normal)
        {
            if (centerPoint == null)
            {
                throw new ArgumentNullException("centerPoint");
            }
            else if (normal == null)
            {
                throw new ArgumentNullException("normal");
            }
            else if (radius <= 0.0)
            {
                throw new ArgumentException(string.Format(Properties.Resources.LessThanZero, "radius"));
            }
            else if (normal.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, normal), "normal");
            }
            normal = normal.IsNormalized ? normal : normal.Normalize();
            var        endAngle = (startAngle + sweepAngle);
            IArcEntity entity   = HostFactory.Factory.ArcByCenterPointRadiusAngle(centerPoint.PointEntity, radius, DSGeometryExtension.DegreesToRadians(startAngle), DSGeometryExtension.DegreesToRadians(endAngle), normal.IVector);

            if (null == entity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSArc.ByCenterPointRadiusAngle"));
            }
            return(entity);
        }
Exemple #13
0
 protected DSArc(DSPoint firstPoint, DSPoint secondPoint, DSPoint thirdPoint, bool persist)
     : base(ByPointsOnCurveCore(firstPoint, secondPoint, thirdPoint), persist)
 {
     InitializeGuaranteedProperties();
     FirstPoint  = firstPoint;
     SecondPoint = secondPoint;
     ThirdPoint  = thirdPoint;
 }
Exemple #14
0
 protected DSBSplineCurve(DSPoint[] points, DSVector startTangent, DSVector endTangent, bool makePeriodic,bool persist)
     : base(ByPointsCore(ref points, startTangent, endTangent, makePeriodic),persist)
 {
     InitializeGuaranteedProperties();
     Points = points;
     StartTangent = startTangent;
     EndTangent = endTangent;
 }
Exemple #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="curves"></param>
 /// <param name="selectPoint"></param>
 /// <param name="autoExtend"></param>
 /// <returns></returns>
 public DSSurface Trim(DSCurve[] curves, DSPoint selectPoint, bool autoExtend)
 {
     if (null == curves)
     {
         throw new System.ArgumentNullException("curves");
     }
     return(Trim(curves, null, null, null, selectPoint, autoExtend));
 }
Exemple #16
0
 protected DSCircle(DSPoint firstPoint, DSPoint secondPoint, DSPoint thirdPoint,bool persist)
     : base(ByPointsOnCurveCore(firstPoint, secondPoint, thirdPoint),persist)
 {
     InitializeGuaranteedProperties();
     FirstPoint = firstPoint;
     SecondPoint = secondPoint;
     ThirdPoint = thirdPoint;
 }
Exemple #17
0
 protected DSCone(DSPoint startPoint, DSPoint endPoint, double startRadius, double endRadius,bool persist)
     : base(ByStartPointEndPointRadiusCore(startPoint, endPoint, startRadius, endRadius),persist)
 {
     InitializeGuaranteedProperties();
     StartPoint = startPoint;
     EndPoint = endPoint;
     StartRadius = startRadius;
     EndRadius = endRadius;
 }
Exemple #18
0
        /// <summary>
        /// Returns the U, V parameter at a given point of a surface
        /// </summary>
        /// <param name="point"></param>
        /// <returns>double[] == the first element is U, the second double is V</returns>
        public double[] ParameterAtPoint(DSPoint point)
        {
            System.Tuple <double, double> parametersTuple = SurfaceEntity.GetUVParameterAtPoint(point.PointEntity);
            List <double> parameters = new List <double>();

            parameters.Add(parametersTuple.Item1);
            parameters.Add(parametersTuple.Item2);
            return(parameters.ToArray());
        }
Exemple #19
0
 protected DSCone(DSPoint startPoint, DSPoint endPoint, double startRadius, double endRadius, bool persist)
     : base(ByStartPointEndPointRadiusCore(startPoint, endPoint, startRadius, endRadius), persist)
 {
     InitializeGuaranteedProperties();
     StartPoint  = startPoint;
     EndPoint    = endPoint;
     StartRadius = startRadius;
     EndRadius   = endRadius;
 }
Exemple #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="planes"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public DSSurface Trim(DSPlane[] planes, DSPoint selectPoint, bool autoExtend)
        {
            if (null == planes)
            {
                throw new System.ArgumentNullException("planes");
            }

            return(Trim(null, planes, null, null, selectPoint, autoExtend));
        }
Exemple #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="solids"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public DSSurface Trim(DSSolid[] solids, DSPoint selectPoint, bool autoExtend)
        {
            if (null == solids)
            {
                throw new System.ArgumentNullException("solids");
            }

            return(Trim(null, null, null, solids, selectPoint, autoExtend));
        }
Exemple #22
0
 protected internal DSPlane(DSPoint origin, DSVector normal, double size, bool display = false, DSGeometry context = null)
     : base(ByOriginNormalCore(origin, ref normal, size), false)
 {
     InitializeGuaranteedProperties();
     Size = size;
     Context = context;
     if (display)
         mDisplayPolygon = CreatePlaneVisuals(size,true);
 }
Exemple #23
0
        /// <summary>
        /// Creates a block with the given name, reference point and from the
        /// specified geometries
        /// </summary>
        /// <param name="blockName">the block name</param>
        /// <param name="referencePoint">the reference point</param>
        /// <param name="contents">the geometries contained in the block</param>
        /// <returns></returns>
        public static DSBlock FromGeometry(string blockName, DSPoint referencePoint,
                                           DSGeometry[] contents)
        {
            DSCoordinateSystem referenceCoordinateSystem = DSCoordinateSystem.Identity();

            referenceCoordinateSystem.Translate(referencePoint.X, referencePoint.Y,
                                                referencePoint.Z);
            return(FromGeometry(blockName, referenceCoordinateSystem, contents));
        }
Exemple #24
0
 protected DSSolid(DSCurve profile, DSPoint axisOrigin, DSVector axisDirection, double startAngle, double sweepAngle, bool persist)
     : base(RevolveCore(profile, axisOrigin, axisDirection, startAngle, sweepAngle), persist)
 {
     InitializeGuaranteedProperties();
     Profile = profile;
     AxisOrigin = axisOrigin;
     AxisDirection = axisDirection;
     StartAngle = startAngle;
     SweepAngle = sweepAngle;
 }
Exemple #25
0
        internal IGeometryEntity[] IntersectWithPoint(DSPoint point)
        {
            if (GeomEntity.DistanceTo(point.PointEntity).EqualsTo(0.0))
            {
                return new IGeometryEntity[] { point.PointEntity }
            }
            ;

            return(null);
        }
Exemple #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public DSSurface Trim(DSSurface surface, DSPoint selectPoint, bool autoExtend)
        {
            if (null == surface)
            {
                throw new System.ArgumentNullException("surface");
            }

            DSSurface[] surfaces = { surface };
            return(Trim(null, null, surfaces, null, selectPoint, autoExtend));
        }
 protected DSRevolvedSurface(DSCurve profile, DSPoint axisOrigin, DSVector axisDirection, double startAngle, double sweepAngle, bool persist)
     : base(ByProfileAxisOriginDirectionAngleCore(profile, axisOrigin, axisDirection, startAngle, sweepAngle), persist)
 {
     InitializeGuaranteedProperties();
     Profile       = profile;
     AxisOrigin    = axisOrigin;
     AxisDirection = axisDirection;
     StartAngle    = startAngle;
     SweepAngle    = sweepAngle;
 }
Exemple #28
0
        private static IPointEntity ByOffsetCore(DSPoint refPoint, double deltaX, double deltaY, double deltaZ)
        {
            if (refPoint == null)
            {
                throw new ArgumentNullException("refPoint");
            }

            var pt = HostFactory.Factory.CreatePoint(refPoint.X + deltaX, refPoint.Y + deltaY, refPoint.Z + deltaZ);

            return(pt);
        }
Exemple #29
0
 protected internal DSPlane(DSPoint origin, DSVector normal, double size, bool display = false, DSGeometry context = null)
     : base(ByOriginNormalCore(origin, ref normal, size), false)
 {
     InitializeGuaranteedProperties();
     Size    = size;
     Context = context;
     if (display)
     {
         mDisplayPolygon = CreatePlaneVisuals(size, true);
     }
 }
Exemple #30
0
        public static bool ArePointsColinear(DSPoint one, DSPoint two, DSPoint three)
        {
            var onePos = one.PointEntity;
            var twoPos = two.PointEntity;
            var thrPos = three.PointEntity;

            var vec12 = onePos.GetVectorTo(twoPos);
            var vec23 = twoPos.GetVectorTo(thrPos);

            return(vec12.IsZeroVector() || vec23.IsZeroVector() || vec12.IsParallel(vec23));
        }
 private DSSurfaceCurvature(DSSurface contextSurface, double u, double v, ICoordinateSystemEntity coordinateSystemEntity)
 {
     FirstPrincipleCurvature  = new DSVector(coordinateSystemEntity.XAxis);
     SecondPrincipleCurvature = new DSVector(coordinateSystemEntity.YAxis);
     GaussianCurvature        = FirstPrincipleCurvature.Length * SecondPrincipleCurvature.Length;
     mPointOnSurface          = DSPoint.ToGeometry(coordinateSystemEntity.Origin, false, contextSurface) as DSPoint;
     U = u;
     V = v;
     ContextSurface    = contextSurface;
     mCoordinateSystem = DSCoordinateSystem.ToCS(coordinateSystemEntity, false);
 }
 private DSSurfaceCurvature(DSSurface contextSurface, double u, double v, ICoordinateSystemEntity coordinateSystemEntity)
 {
     FirstPrincipleCurvature = new DSVector(coordinateSystemEntity.XAxis);
     SecondPrincipleCurvature = new DSVector(coordinateSystemEntity.YAxis);
     GaussianCurvature = FirstPrincipleCurvature.Length * SecondPrincipleCurvature.Length;
     mPointOnSurface = DSPoint.ToGeometry(coordinateSystemEntity.Origin, false, contextSurface) as DSPoint;
     U = u;
     V = v;
     ContextSurface = contextSurface;
     mCoordinateSystem = DSCoordinateSystem.ToCS(coordinateSystemEntity, false);
 }
Exemple #33
0
        private static ICircleEntity ByPointsOnCurveCore(DSPoint firstPoint, DSPoint secondPoint, DSPoint thirdPoint)
        {
            if (firstPoint == null)
            {
                throw new ArgumentNullException("firstPoint");
            }
            else if (secondPoint == null)
            {
                throw new ArgumentNullException("secondPoint");
            }
            else if (thirdPoint == null)
            {
                throw new ArgumentNullException("thirdPoint");
            }
            else if (firstPoint.Equals(secondPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "first point", "second point"), "firstPoint, secondPoint");
            }
            else if (secondPoint.Equals(thirdPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "second point", "thrid point"), "secondPoint, thirdPoint");
            }
            else if (thirdPoint.Equals(firstPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "third point", "first point"), "thirdPoint, firstPoint");
            }
            else if (DSGeometryExtension.ArePointsColinear(firstPoint, secondPoint, thirdPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.PointsColinear, "first, second and thrid points"), "firstPoint, secondPoint, thirdPoint");
            }

            /*
             * Vector normal = null;
             * var centerPt = Utils.GetCircumCenter(firstPoint, secondPoint, thirdPoint, out normal);
             * if (centerPt == null || normal == null)
             * {
             *  return null;
             * }
             * double rad = firstPoint.PointEntity.DistanceTo(centerPt.PointEntity);
             * if( rad <= 0.0)
             * {
             *  return null;
             * }
             */
            var entity = HostFactory.Factory.CircleByPointsOnCurve(firstPoint.PointEntity,
                                                                   secondPoint.PointEntity, thirdPoint.PointEntity);

            if (null == entity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSCircle.ByPointsOnCurve"));
            }
            return(entity);
        }
Exemple #34
0
        public DSGeometry[] Intersect(DSGeometry other)
        {
            if (null == other)
            {
                throw new ArgumentNullException("other");
            }

            IGeometryEntity[] geoms = null;
            DSPlane           plane = other as DSPlane;

            if (plane != null)
            {
                geoms = IntersectWithPlane(plane);
            }
            else
            {
                DSSurface surf = other as DSSurface;
                if (surf != null)
                {
                    geoms = IntersectWithSurface(surf);
                }
                else
                {
                    DSSolid solid = other as DSSolid;
                    if (solid != null)
                    {
                        geoms = IntersectWithSolid(solid);
                    }
                    else
                    {
                        DSCurve curve = other as DSCurve;
                        if (curve != null)
                        {
                            geoms = IntersectWithCurve(curve);
                        }
                        else
                        {
                            DSPoint point = other as DSPoint;
                            if (null != point)
                            {
                                geoms = IntersectWithPoint(point);
                            }
                            else
                            {
                                throw new System.InvalidOperationException(string.Format(Properties.Resources.InvalidIntersect, GetType().Name, other.GetType().Name));
                            }
                        }
                    }
                }
            }

            return(geoms.ToArray <DSGeometry, IGeometryEntity>(true));
        }
Exemple #35
0
        private static ISphereEntity ByCenterPointRadiusCore(DSPoint centerPoint, double radius)
        {
            if (radius.LessThanOrEqualTo(0.0))
                throw new ArgumentException(string.Format(Properties.Resources.LessThanZero, "radius"), "radius");
            if (centerPoint == null)
                throw new ArgumentNullException("centerPoint");

            ISphereEntity entity = HostFactory.Factory.SphereByCenterPointRadius(centerPoint.PointEntity, radius);
            if (null == entity)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSSphere.ByCenterPointRadius"));
            return entity;
        }
Exemple #36
0
 public static DSVector ByCoordinates(DSCoordinateSystem coordinateSystem, double x, double y, double z)
 {
     if (coordinateSystem == null)
     {
         throw new System.ArgumentNullException("coordinateSystem");
     }
     using (var p = DSPoint.ByCartesianCoordinates(coordinateSystem, x, y, z))
     {
         DSVector vec = coordinateSystem.Origin.DirectionTo(p);
         vec.ContextCoordinateSystem = coordinateSystem;
         return(vec);
     }
 }
Exemple #37
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="otherPoint"></param>
        /// <returns></returns>
        public DSVector DirectionTo(DSPoint otherPoint)
        {
            if (otherPoint == null)
            {
                return(null);
            }

            var delx = otherPoint.X - X;
            var dely = otherPoint.Y - Y;
            var delz = otherPoint.Z - Z;

            return(new DSVector(delx, dely, delz));
        }
Exemple #38
0
        public double DistanceTo(DSPoint otherPoint)
        {
            if (otherPoint == null)
            {
                return(0.0);
            }

            var delx   = otherPoint.X - X;
            var dely   = otherPoint.Y - Y;
            var delz   = otherPoint.Z - Z;
            var sqDist = delx * delx + dely * dely + delz * delz;

            return(Math.Sqrt(sqDist));
        }
Exemple #39
0
        /// <summary>
        /// Returns a normal to the surface at the specified point
        /// </summary>
        /// <param name="pointOnSurface">Point on the surface at which the normal is required</param>
        /// <returns></returns>
        public DSVector NormalAtPoint(DSPoint pointOnSurface)
        {
            if (pointOnSurface == null)
            {
                throw new System.ArgumentNullException("pointOnSurface");
            }
            IVector normal = SurfaceEntity.GetNormalAtPoint(pointOnSurface.PointEntity);

            if (normal == null)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSSurface.NormalAtPoint"));
            }
            return(new DSVector(normal));
        }
Exemple #40
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="curves"></param>
        /// <param name="planes"></param>
        /// <param name="surfaces"></param>
        /// <param name="solids"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public DSSurface Trim(DSCurve[] curves, DSPlane[] planes, DSSurface[] surfaces, DSSolid[] solids, DSPoint selectPoint, bool autoExtend)
        {
            if (null == selectPoint)
                throw new System.ArgumentNullException("selectPoint");

            ICurveEntity[] hostCurves = curves.ConvertAll(DSGeometryExtension.ToEntity<DSCurve, ICurveEntity>);
            IPlaneEntity[] hostPlanes = planes.ConvertAll(DSGeometryExtension.ToEntity<DSPlane, IPlaneEntity>);
            ISurfaceEntity[] hostSurfaces = surfaces.ConvertAll(DSGeometryExtension.ToEntity<DSSurface, ISurfaceEntity>);
            ISolidEntity[] hostSolids = solids.ConvertAll(DSGeometryExtension.ToEntity<DSSolid, ISolidEntity>);

            IPointEntity hostPoint = selectPoint.PointEntity;

            if (hostCurves == null && hostPlanes == null && hostSurfaces == null && hostSolids == null)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "DSGeometry", "DSSurface.Trim"));

            ISurfaceEntity trimSurface = SurfaceEntity.Trim(hostCurves, hostPlanes, hostSurfaces, hostSolids, hostPoint, autoExtend);

            //For trim operation, if the return value is not null, hide the original tools and surfaces.
            if (null != trimSurface)
            {
                Hide(curves);
                Hide(planes);
                Hide(surfaces);
                Hide(solids);
                SetVisibility(false);
            }

            return trimSurface.ToSurf(true, this);
        }
Exemple #41
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="curves"></param>
 /// <param name="selectPoint"></param>
 /// <param name="autoExtend"></param>
 /// <returns></returns>
 public DSSurface Trim(DSCurve[] curves, DSPoint selectPoint, bool autoExtend)
 {
     if (null == curves)
         throw new System.ArgumentNullException("curves");
     return Trim(curves, null, null, null, selectPoint, autoExtend);
 }
Exemple #42
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="planes"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public DSSurface Trim(DSPlane[] planes, DSPoint selectPoint, bool autoExtend)
        {
            if(null == planes)
                throw new System.ArgumentNullException("planes");

            return Trim(null, planes, null, null, selectPoint, autoExtend);
        }
Exemple #43
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public DSSurface Trim(DSSurface surface, DSPoint selectPoint, bool autoExtend)
        {
            if(null == surface)
                throw new System.ArgumentNullException("surface");

            DSSurface[] surfaces = {surface};
            return Trim(null, null, surfaces, null, selectPoint, autoExtend);
        }
Exemple #44
0
 private static ICircleEntity ByPointsOnCurveCore(DSPoint firstPoint, DSPoint secondPoint, DSPoint thirdPoint)
 {
     if (firstPoint == null)
     {
         throw new ArgumentNullException("firstPoint");
     }
     else if (secondPoint == null)
     {
         throw new ArgumentNullException("secondPoint");
     }
     else if (thirdPoint == null)
     {
         throw new ArgumentNullException("thirdPoint");
     }
     else if (firstPoint.Equals(secondPoint))
     {
         throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "first point", "second point"), "firstPoint, secondPoint");
     }
     else if (secondPoint.Equals(thirdPoint))
     {
         throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "second point", "thrid point"), "secondPoint, thirdPoint");
     }
     else if (thirdPoint.Equals(firstPoint))
     {
         throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "third point", "first point"), "thirdPoint, firstPoint");
     }
     else if (DSGeometryExtension.ArePointsColinear(firstPoint, secondPoint, thirdPoint))
     {
         throw new ArgumentException(string.Format(Properties.Resources.PointsColinear, "first, second and thrid points"), "firstPoint, secondPoint, thirdPoint");
     }
     /*
     Vector normal = null;
     var centerPt = Utils.GetCircumCenter(firstPoint, secondPoint, thirdPoint, out normal);
     if (centerPt == null || normal == null)
     {
         return null;
     }
     double rad = firstPoint.PointEntity.DistanceTo(centerPt.PointEntity);
     if( rad <= 0.0)
     {
         return null;
     }
     */
     var entity = HostFactory.Factory.CircleByPointsOnCurve(firstPoint.PointEntity,
                                                 secondPoint.PointEntity, thirdPoint.PointEntity);
     if (null == entity)
         throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSCircle.ByPointsOnCurve"));
     return entity;
 }
Exemple #45
0
 /// <summary>
 /// Construct a Surface by revolving the profile curve about an axis
 /// defined by axisOrigin point and axisDirection Vector.
 /// Assuming sweep angle = 360 and start angle = 0.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axisOrigin">Origin Point for axis of revolution.</param>
 /// <param name="axisDirection">Direction Vector for axis of revolution.</param>
 /// <returns>RevolvedSurface</returns>
 public static DSRevolvedSurface Revolve(DSCurve profile, DSPoint axisOrigin, DSVector axisDirection)
 {
     return DSRevolvedSurface.ByProfileAxisOriginDirection(profile, axisOrigin, axisDirection);
 }
Exemple #46
0
 protected DSBSplineCurve(DSPoint[] controlVertices, int degree, bool makePeriodic,bool persist)
     : base(ByControlVerticesCore(controlVertices, ref degree, makePeriodic), persist)
 {
     InitializeGuaranteedProperties();
 }
Exemple #47
0
        /// <summary>
        /// Constructs a Bspline curve interpolating the given set of input 
        /// points and tangent to the first and second tangent vectors at the 
        /// start and end points respectively with degree 3.
        /// </summary>
        /// <param name="points">Array of points</param>
        /// <param name="startTangent">Start tangent vector</param>
        /// <param name="endTangent">End tangent vector</param>
        /// <returns>BSplineCurve</returns>
        public static DSBSplineCurve ByPoints(DSPoint[] points, DSVector startTangent, DSVector endTangent)
        {
            if (startTangent == null || endTangent == null ||
                startTangent.IsZeroVector() || endTangent.IsZeroVector())
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "points"), "points");
            }

            return ByPoints(points, startTangent, endTangent, false);
        }
Exemple #48
0
 /// <summary>
 /// Constructs a Bspline curve from a given list of input points,  The 
 /// 'makePeriodic' flag determines if the curve should be closed with 
 /// C1 continuity. The degree is 3. 
 /// </summary>
 /// <param name="points">Array of points</param>
 /// <param name="makePeriodic">Flag to make it periodic</param>
 /// <returns>BSplineCurve</returns>
 public static DSBSplineCurve ByPoints(DSPoint[] points, bool makePeriodic)
 {
     return ByPoints(points, null, null, makePeriodic);
 }
Exemple #49
0
 /// <summary>
 /// Constructs a non-periodic Bspline curve by fitting the given array 
 /// of points. The degree is 3. 
 /// </summary>
 /// <param name="points">Array of points</param>
 /// <returns>BSplineCurve</returns>
 public static DSBSplineCurve ByPoints(DSPoint[] points)
 {
     return ByPoints(points, false);
 }
Exemple #50
0
 /// <summary>
 /// Constructs a Bspline curve from a given list of input control 
 /// vertices and degree,  The 'makePeriodic' flag determines if the 
 /// curve should be closed with C1 continuity.
 /// </summary>
 /// <param name="controlVertices">Array of points</param>
 /// <param name="degree">Degree of the curve</param>
 /// <param name="makePeriodic">Flag to make it periodic</param>
 /// <returns>BSplineCurve</returns>
 public static DSBSplineCurve ByControlVertices(DSPoint[] controlVertices, int degree, bool makePeriodic)
 {
     return new DSBSplineCurve(controlVertices, degree, makePeriodic, true);
 }
Exemple #51
0
 /// <summary>
 /// Constructs a non-periodic BSplineCurve with given control vertices and degree.
 /// </summary>
 /// <param name="controlVertices">Array of points</param>
 /// <param name="degree">Degree of the curve</param>
 /// <returns>BSplineCurve</returns>
 public static DSBSplineCurve ByControlVertices(DSPoint[] controlVertices, int degree )
 {
     return ByControlVertices(controlVertices, degree, false);
 }
Exemple #52
0
        private static IBSplineCurveEntity ByControlVerticesCore(DSPoint[] controlVertices, ref int degree, bool makePeriodic)
        {
            IPointEntity[] hosts = controlVertices.ConvertAll(DSGeometryExtension.ToEntity<DSPoint, IPointEntity>);
            if (hosts == null)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "controlVertices", "DSBSplineCurve"), "controlVertices");

            if (degree < 1 || degree > 11)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "degree", "one"), "degree");
            }
            if (hosts.AreCoincident())
                throw new System.ArgumentException(string.Format(Properties.Resources.PointsCoincident, "controlVertices"), "controlVertices"); //Can't create BSpline curve with all coincident points.

            // making sure if # of controlVertices > degree by atleast 1
            int udiff = hosts.Length - degree;
            if (udiff < 1)
                degree += udiff - 1; //Fix DID DG-1464903

            var ent = HostFactory.Factory.BSplineByControlVertices(hosts, degree, makePeriodic);
            if (null == ent)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSBSplineCurve.ByControlVertices"));
            return ent;
        }
Exemple #53
0
 /// <summary>
 /// Constructs a solid cone defined by a start and end point on its axis and the start and end radii of its base and top respectively.
 /// </summary>
 /// <param name="startPoint">The start point on the axis of the cone</param>
 /// <param name="endPoint">The end point on the axis of the cone</param>
 /// <param name="startRadius">The radius of the base of the cone</param>
 /// <param name="endRadius">The radius of the top of the cone</param>
 /// <returns></returns>
 public static DSCone ByStartPointEndPointRadius(DSPoint startPoint, DSPoint endPoint, double startRadius, double endRadius)
 {
     return new DSCone(startPoint, endPoint, startRadius, endRadius, true);
 }
Exemple #54
0
 /// <summary>
 /// Internal function to create BSplineCurve by fit points.
 /// </summary>
 /// <param name="points">Array of points</param>
 /// <param name="startTangent">Start tangent vector</param>
 /// <param name="endTangent">End tangent vector</param>
 /// <param name="makePeriodic">Flag to make it periodic</param>
 /// <returns>BSplineCurve</returns>
 private static DSBSplineCurve ByPoints(DSPoint[] points, DSVector startTangent, DSVector endTangent, bool makePeriodic)
 {
     return new DSBSplineCurve(points, startTangent, endTangent, makePeriodic, true);
 }
Exemple #55
0
 /// <summary>
 /// Construct a Surface by revolving the profile curve about an axis 
 /// defined by axisOrigin point and axisDirection Vector. startAngle 
 /// determines where the curve starts to revolve, sweepAngle determines 
 /// the extent of the revolve.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axisOrigin">Origin Point for axis of revolution.</param>
 /// <param name="axisDirection">Direction Vector for axis of revolution.</param>
 /// <param name="startAngle">Start Angle in degreee at which curve starts to revolve.</param>
 /// <param name="sweepAngle">Sweep Angle in degree to define the extent of revolve.</param>
 /// <returns>RevolvedSurface</returns>
 public static DSRevolvedSurface Revolve(DSCurve profile, DSPoint axisOrigin, DSVector axisDirection, double startAngle, double sweepAngle)
 {
     return DSRevolvedSurface.ByProfileAxisOriginDirectionAngle(profile, axisOrigin, axisDirection, startAngle, sweepAngle);
 }
Exemple #56
0
        private static IBSplineCurveEntity ByPointsCore(ref DSPoint[] points, DSVector startTangent, DSVector endTangent, bool makePeriodic)
        {
            IPointEntity[] hosts = points.ConvertAll(DSGeometryExtension.ToEntity<DSPoint, IPointEntity>);
            if (hosts == null || hosts.Length < 2)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "points"), "points");
            }
            if (hosts.AreCoincident())
                throw new System.ArgumentException(string.Format(Properties.Resources.PointsCoincident, "points"), "points"); //Can't create BSpline curve with all coincident points.

            IBSplineCurveEntity ent = null;
            if (null != startTangent && null != endTangent)
                ent = HostFactory.Factory.BSplineByPoints(hosts, startTangent.IVector, endTangent.IVector);
            else
                ent = HostFactory.Factory.BSplineByPoints(hosts, makePeriodic);
            if (ent == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSBSplineCurve.ByPoints"));
            points = hosts.ToArray<DSPoint, IPointEntity>(false);
            return ent;
        }
Exemple #57
0
 /// <summary>
 /// Returns a normal to the surface at the specified point
 /// </summary>
 /// <param name="pointOnSurface">Point on the surface at which the normal is required</param>
 /// <returns></returns>
 public DSVector NormalAtPoint(DSPoint pointOnSurface)
 {
     if (pointOnSurface == null)
         throw new System.ArgumentNullException("pointOnSurface");
     IVector normal = SurfaceEntity.GetNormalAtPoint(pointOnSurface.PointEntity);
     if(normal == null)
         throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSSurface.NormalAtPoint"));
     return new DSVector(normal);
 }
Exemple #58
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="solids"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public DSSurface Trim(DSSolid[] solids, DSPoint selectPoint, bool autoExtend)
        {
            if(null == solids)
                throw new System.ArgumentNullException("solids");

            return Trim(null, null, null, solids, selectPoint, autoExtend);
        }
Exemple #59
0
        private static IConeEntity ByStartPointEndPointRadiusCore(DSPoint startPoint, DSPoint endPoint, double startRadius, double endRadius)
        {
            if (startRadius.LessThanOrEqualTo(0.0))
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "start radius"), "startRadius");
            if (endRadius < 0.0)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "end radius"), "endRadius");
            if (null == startPoint)
                throw new System.ArgumentNullException("startPoint");
            if (null == endPoint)
                throw new System.ArgumentNullException("endPoint");
            if (startPoint.DistanceTo(endPoint).EqualsTo(0.0))
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroDistance, "start point", "end point"), "startPoint, endPoint");

            IConeEntity entity = HostFactory.Factory.ConeByPointsRadius(startPoint.PointEntity, endPoint.PointEntity, startRadius, endRadius);
            if (null == entity)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCone.ByStartPointEndPointRadius"));
            return entity;
        }
Exemple #60
0
 /// <summary>
 /// Returns the U, V parameter at a given point of a surface
 /// </summary>
 /// <param name="point"></param>
 /// <returns>double[] == the first element is U, the second double is V</returns>
 public double[] ParameterAtPoint(DSPoint point)
 {
     System.Tuple<double, double> parametersTuple = SurfaceEntity.GetUVParameterAtPoint(point.PointEntity);
     List<double> parameters = new List<double>();
     parameters.Add(parametersTuple.Item1);
     parameters.Add(parametersTuple.Item2);
     return parameters.ToArray();
 }