Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Translates any geometry type by the given distance in the given
        /// direction.
        /// </summary>
        /// <param name="direction">Displacement direction.</param>
        /// <param name="distance">Displacement distance along given direction.</param>
        /// <returns>Transformed Geometry.</returns>
        public DSGeometry Translate(DSVector direction, double distance)
        {
            DSVector   offset = direction.Normalize().MultiplyBy(distance);
            DSGeometry geom   = Translate(offset);

            SetDisplayPropertiesTo(geom.Display);
            return(geom);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool IsPerpendicular(DSVector other)
        {
            if (other == null)
            {
                throw new System.ArgumentNullException("other");
            }
            var normalizedThis  = Normalize();
            var normalizedOther = other.Normalize();

            var dotProd = normalizedThis.Dot(normalizedOther);

            return(DSGeometryExtension.Equals(Math.Abs(dotProd), 0.0));
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="persist"></param>
        /// <returns></returns>
        internal DSPoint Translate(DSVector offset, bool persist)
        {
            if (offset == null)
            {
                throw new ArgumentNullException("direction");
            }

            IPointEntity pthost = PointEntity.Add(offset);
            DSPoint      pt     = pthost.ToPoint(persist, this);

            //  setup backlinks
            pt.Direction = offset.Normalize();
            pt.Distance  = offset.Length;

            return(pt);
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="u"></param>
        /// <param name="v"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        internal DSPoint PointAtParametersCore(ref double u, ref double v, double offset)
        {
            bool uchange = DSGeometryExtension.ClipParamRange(ref u);
            bool vchange = DSGeometryExtension.ClipParamRange(ref v);
            // TO DO - throw a warning each time a condition above is satisfied.
            //throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "u or v parameter", "Surface.PointAtParameters"));

            IPointEntity pt = SurfaceEntity.PointAtParameter(u, v);

            if (!offset.EqualsTo(0.0))
            {
                DSVector     normal      = new DSVector(SurfaceEntity.NormalAtPoint(pt));
                DSVector     translation = normal.Normalize().Scale(offset);
                IPointEntity offsetPt    = pt.Add(translation);
                pt.Dispose();
                pt = offsetPt;
            }
            return(pt.ToPoint(true, this));
        }
Пример #8
0
        private static ILineEntity GetPerpBisector(DSPoint startPt, DSPoint endPt,
                                                   IPlaneEntity planeOfCircle)
        {
            DSVector dir = startPt.DirectionTo(endPt);

            dir = dir.Normalize();

            IPointEntity midPt = HostFactory.Factory.CreatePoint((startPt.X + endPt.X) / 2, (startPt.Y + endPt.Y) / 2, (startPt.Z + endPt.Z) / 2);

            //  get the perpendicular plane to plane of circle at mid point of segment[startPt, endPt]
            //
            IPlaneEntity perpPlane = HostFactory.Factory.PlaneByOriginNormal(midPt, dir.IVector);

            //  this intersection results in line perp to segment[startPt, endPt] & plane normal
            //  and happens to be the perpBisector of mentioned segment in planeOfCircle
            //
            ILineEntity perpBisector = planeOfCircle.IntersectWith(perpPlane);

            return(perpBisector);
        }
Пример #9
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, DSVector direction)
        {
            if (null == profile || direction.IsZeroVector())
            {
                return(null);
            }

            using (IPointEntity startPt = profile.PointAtParameter(0.5))
            {
                DSVector 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());
                        }
                    }
                }
            }
        }
Пример #10
0
        private static IPlaneEntity ByOriginNormalCore(DSPoint origin, ref DSVector 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, "DSPlane.ByOriginNormal"));
            }
            return(entity);
        }
Пример #11
0
        private static IArcEntity ByCenterPointStartPointSweepAngleCore(DSPoint centerPoint, DSPoint startPoint, double sweepAngle, ref DSVector 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, DSGeometryExtension.DegreesToRadians(sweepAngle), normal.IVector);

            if (null == entity)
            {
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSArc.ByCenterPointStartPointSweepAngle"));
            }
            return(entity);
        }
Пример #12
0
        internal static DSCoordinateSystem ByOriginVectors(DSPoint origin, DSVector xAxis, DSVector yAxis, DSVector zAxis,
            bool isSheared, bool isNormalized, bool visible)
        {
            if (origin == null)
                throw new System.ArgumentNullException("origin");
            else if (xAxis == null)
                throw new System.ArgumentNullException("xAxis");
            else if (yAxis == null)
                throw new System.ArgumentNullException("yAxis");
            else if (zAxis == null)
                throw new System.ArgumentNullException("zAxis");
            else if (xAxis.IsZeroVector())
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "x axis"), "xAxis");
            else if (yAxis.IsZeroVector())
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "y axis"), "yAxis");
            else if (zAxis.IsZeroVector())
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "z axis"), "zAxis");
            else if (xAxis.IsParallel(yAxis))
                throw new System.ArgumentException(string.Format(Properties.Resources.IsParallel, "x axis", "y axis", "DSCoordinateSystem.ByOriginVectors"), "xAxis, yAxis");
            else if (!isSheared && (!xAxis.IsPerpendicular(yAxis) || !yAxis.IsPerpendicular(zAxis) || !zAxis.IsPerpendicular(xAxis)))
            {
                //  this is not the case for sheared but axes are not orthogonal
                //
                zAxis = xAxis.Cross(yAxis);
                yAxis = zAxis.Cross(xAxis);
            }

            if (isNormalized)
            {
                xAxis = xAxis.Normalize();
                yAxis = yAxis.Normalize();
                zAxis = zAxis.Normalize();
            }

            var cs = HostFactory.Factory.CoordinateSystemByData(null); //create identity matrix
            if (null == cs)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.ByOriginVectors"));

            cs.Set(origin.PointEntity, xAxis.IVector, yAxis.IVector, zAxis.IVector);
            var coordSys = new DSCoordinateSystem(cs, visible);

            return coordSys;
        }
Пример #13
0
        /// <summary>
        /// Translates the coordinate system in the direction of the vector and by the distance specified
        /// </summary>
        /// <param name="translationVector">The direction of translation</param>
        /// <param name="distance">The distance of translation</param>
        /// <returns></returns>
        public DSCoordinateSystem Translate(DSVector translationVector, double distance)
        {
            if (translationVector == null)
            {
                throw new System.ArgumentNullException("translationVector");
            }
            translationVector = translationVector.Normalize().MultiplyBy(distance);
            var translatedCSEntity = CSEntity.Translate(translationVector.IVector);
            var cs = new DSCoordinateSystem(translatedCSEntity, true);

            return cs;
        }
Пример #14
0
        private static IPlaneEntity ByOriginNormalCore(DSPoint origin, ref DSVector 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, "DSPlane.ByOriginNormal"));
            return entity;
        }
Пример #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool IsPerpendicular(DSVector other)
        {
            if (other == null)
            {
                throw new System.ArgumentNullException("other");
            }
            var normalizedThis = Normalize();
            var normalizedOther = other.Normalize();

            var dotProd = normalizedThis.Dot(normalizedOther);
            return DSGeometryExtension.Equals(Math.Abs(dotProd), 0.0);
        }
Пример #16
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;
        }
Пример #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="persist"></param>
        /// <returns></returns>
        internal DSPoint Translate(DSVector offset, bool persist)
        {
            if (offset == null)
            {
                throw new ArgumentNullException("direction");
            }

            IPointEntity pthost = PointEntity.Add(offset);
            DSPoint pt = pthost.ToPoint(persist, this);

            //  setup backlinks
            pt.Direction = offset.Normalize();
            pt.Distance = offset.Length;

            return pt;
        }
Пример #18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="u"></param>
        /// <param name="v"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        internal DSPoint PointAtParametersCore(ref double u, ref double v, double offset)
        {
            bool uchange = DSGeometryExtension.ClipParamRange(ref u);
            bool vchange = DSGeometryExtension.ClipParamRange(ref v);
            // TO DO - throw a warning each time a condition above is satisfied.
            //throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "u or v parameter", "Surface.PointAtParameters"));

            IPointEntity pt = SurfaceEntity.PointAtParameter(u, v);
            if (!offset.EqualsTo(0.0))
            {
                DSVector normal = new DSVector(SurfaceEntity.NormalAtPoint(pt));
                DSVector translation = normal.Normalize().Scale(offset);
                IPointEntity offsetPt = pt.Add(translation);
                pt.Dispose();
                pt = offsetPt;
            }
            return pt.ToPoint(true, this);
        }
Пример #19
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;
 }
Пример #20
0
 private static IArcEntity ByCenterPointStartPointSweepAngleCore(DSPoint centerPoint, DSPoint startPoint, double sweepAngle, ref DSVector 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, DSGeometryExtension.DegreesToRadians(sweepAngle), normal.IVector);
     if (null == entity)
         throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSArc.ByCenterPointStartPointSweepAngle"));
     return entity;
 }
Пример #21
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;
        }