Esempio n. 1
0
        private static IArcEntity ByCenterPointRadiusAngleCore(Point centerPoint, double radius, double startAngle, double sweepAngle, ref Vector 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, GeometryExtension.DegreesToRadians(startAngle), GeometryExtension.DegreesToRadians(endAngle), normal.IVector);

            if (null == entity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "Arc.ByCenterPointRadiusAngle"));
            }
            return(entity);
        }
Esempio n. 2
0
        private static ICircleEntity ByCenterPointRadiusCore(Point centerPoint, double radius, ref Vector 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, "Circle.ByCenterPointRadius"));
            }
            return(entity);
        }
Esempio n. 3
0
        private static ILineEntity ByStartPointDirectionLengthCore(Point startPt, Vector 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
            Vector      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, "Line.ByStartPointDirectionLength"));
            }

            return(entity);
        }
Esempio n. 4
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 Point Project(Surface contextSurface, Vector 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");
            }

            Point 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);
        }
Esempio n. 5
0
        /// <summary>
        /// Constructors a point by projecting a point on a plane with given project direction.
        /// </summary>
        /// <param name="contextPlane">Plane of projection</param>
        /// <param name="direction">Projection direction</param>
        /// <returns>Point</returns>
        public Point Project(Plane contextPlane, Vector direction)
        {
            if (contextPlane == null)
            {
                throw new ArgumentNullException("contextPlane");
            }
            else if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }
            else if (direction.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, "direction"));
            }
            else if (direction.IsPerpendicular(contextPlane.Normal))
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsParallel, "contextPlane", "direction", "Point.Project"));
            }

            var pt = contextPlane.Project(this, direction);

            pt.Context        = contextPlane;
            pt.ReferencePoint = this;
            pt.Direction      = direction;
            pt.Persist();
            return(pt);
        }
Esempio n. 6
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 BSplineCurve ByPoints(Point[] points, Vector startTangent, Vector 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));
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="point"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public Point Project(Point point, Vector direction)
        {
            if (point == null || direction == null || direction.IsZeroVector())
            {
                return(null);
            }

            IPointEntity projectedPt = PlaneEntity.Project(point.PointEntity, direction.IVector);

            if (null == projectedPt)
            {
                return(null);
            }
            return(projectedPt.ToPoint(true, this));
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pts"></param>
        /// <param name="startTangent"></param>
        /// <param name="endTangent"></param>
        /// <returns></returns>
        public static BSplineCurve ByPoints(Point[] pts, Vector startTangent, Vector endTangent)
        {
            if (pts == null || startTangent == null || endTangent == null ||
                startTangent.IsZeroVector() || endTangent.IsZeroVector())
            {
                return(null);
            }

            IBSplineCurveHost ent = HostFactory.Factory.BSplineByPoints(pts.ToHostArray(), startTangent, endTangent);
            var spline            = new BSplineCurve(ent, true);

            spline.Points       = pts;
            spline.Degree       = 3;
            spline.StartTangent = startTangent;
            spline.EndTangent   = endTangent;

            return(spline);
        }
Esempio n. 9
0
        /// <summary>
        /// Constructs a point by projecting a point on solid with given
        /// project direction.
        /// </summary>
        /// <param name="contextSolid">The solid on which the projection is to be made.</param>
        /// <param name="direction">The direction vector of the projection</param>
        /// <returns>Projected point on solid</returns>
        public Point Project(Solid contextSolid, Vector direction)
        {
            if (null == contextSolid)
            {
                throw new ArgumentNullException("contextSurface");
            }
            if (null == direction || direction.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, direction, "Project on surface"), "direction");
            }

            Point pt = ProjectOnGeometry(contextSolid, direction);

            pt.Context        = contextSolid;
            pt.Direction      = direction;
            pt.ReferencePoint = this;

            return(pt);
        }
Esempio n. 10
0
        /// <summary>
        /// Internal utility method
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="distance"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        internal static IBSplineSurfaceEntity[] ExtrudeAsBSplineSurfaces(this ICurveEntity profile, double distance, Vector direction)
        {
            if (null == profile || direction.IsZeroVector())
            {
                return(null);
            }

            using (IPointEntity startPt = profile.PointAtParameter(0.5))
            {
                Vector offset = direction.Normalize().Scale(distance);
                using (IPointEntity endPt = startPt.CopyAndTranslate(offset.IVector) as IPointEntity)
                {
                    using (ILineEntity path = HostFactory.Factory.LineByStartPointEndPoint(startPt, endPt))
                    {
                        using (ISurfaceEntity surf = HostFactory.Factory.SurfaceBySweep(profile, path))
                        {
                            return(surf.ConvertToBSplineSurface());
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Constructs a point by projecting a point on a curve with given project direction.
        /// </summary>
        /// <param name="curve">the curve on which the projection is to be made.</param>
        /// <param name="direction">the direction vector of the projection</param>
        /// <returns></returns>
        public Point Project(Curve curve, Vector direction)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }
            else if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }
            else if (direction.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, "direction"));
            }

            var pt = curve.Project(this, direction);

            pt.Context        = curve;
            pt.ReferencePoint = this;
            pt.Direction      = direction;
            pt.Persist();
            return(pt);
        }
Esempio n. 12
0
        private static ICircleEntity By2PointsCore(Point firstPoint, Point secondPoint, ref Vector normal)
        {
            if (null == firstPoint)
            {
                throw new ArgumentNullException("firstPoint");
            }
            if (null == secondPoint)
            {
                throw new ArgumentNullException("secondPoint");
            }
            if (null == normal)
            {
                throw new ArgumentNullException("normal");
            }
            if (firstPoint.Equals(secondPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "first point", "second point"), "firstPoint, secondPoint");
            }
            if (normal.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, "normal"), "normal");
            }

            var fptPos = firstPoint.PointEntity;
            var sptPos = secondPoint.PointEntity;
            var cptPos = HostFactory.Factory.CreatePoint((fptPos.X + sptPos.X) / 2.0,
                                                         (fptPos.Y + sptPos.Y) / 2.0,
                                                         (fptPos.Z + sptPos.Z) / 2.0);
            var centerPt     = cptPos.ToPoint(false, null);
            var circleEntity = Circle.ByCenterPointRadiusCore(centerPt, cptPos.DistanceTo(fptPos), ref normal);

            if (circleEntity == null)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "Circle.By2Points"));
            }
            return(circleEntity);
        }
Esempio n. 13
0
        private static IPlaneEntity ByOriginNormalCore(Point origin, ref Vector normal, double size)
        {
            if (origin == null)
            {
                throw new ArgumentNullException("origin");
            }
            else if (normal == null)
            {
                throw new ArgumentNullException("normal");
            }
            else if (normal.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, normal), "normal");
            }

            normal = normal.IsNormalized ? normal : normal.Normalize();
            IPlaneEntity entity = HostFactory.Factory.PlaneByOriginNormal(origin.PointEntity, normal.IVector);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Plane.ByOriginNormal"));
            }
            return(entity);
        }
Esempio n. 14
0
        private static IArcEntity ByCenterPointStartPointSweepAngleCore(Point centerPoint, Point startPoint, double sweepAngle, ref Vector normal)
        {
            if (centerPoint == null)
            {
                throw new ArgumentNullException("centerPoint");
            }
            else if (startPoint == null)
            {
                throw new ArgumentNullException("startPoint");
            }
            else if (normal == null)
            {
                throw new ArgumentNullException("normal");
            }
            else if (normal.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, "normal vector"), "normal");
            }
            else if (centerPoint.Equals(startPoint))
            {
                throw new ArgumentException(string.Format(Properties.Resources.EqualGeometry, "center point", "start point"), "centerPoint, startPoint");
            }
            else if (sweepAngle == 0.0)
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroAngle, "sweep"), "sweepAngle");
            }
            normal = normal.IsNormalized ? normal : normal.Normalize();
            var entity = HostFactory.Factory.ArcByCenterPointStartPointSweepAngle(centerPoint.PointEntity,
                                                                                  startPoint.PointEntity, GeometryExtension.DegreesToRadians(sweepAngle), normal.IVector);

            if (null == entity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "Arc.ByCenterPointStartPointSweepAngle"));
            }
            return(entity);
        }