Exemple #1
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 #2
0
 private void InitializeGuaranteedProperties()
 {
     Radius     = ArcEntity.Radius;
     StartAngle = DSGeometryExtension.RadiansToDegrees(ArcEntity.StartAngle);
     SweepAngle = DSGeometryExtension.RadiansToDegrees(ArcEntity.SweepAngle);
     Normal     = new DSVector(ArcEntity.Normal);
 }
Exemple #3
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 #4
0
        internal override IGeometryEntity[] ProjectOn(DSGeometry other, DSVector direction)
        {
            IVector   dir  = direction.IVector;
            DSSurface surf = other as DSSurface;

            if (null != surf)
            {
                return(surf.SurfaceEntity.Project(PointEntity, dir));
            }

            DSCurve curve = other as DSCurve;

            if (null != curve)
            {
                IPointEntity pt = curve.CurveEntity.Project(PointEntity, dir);
                return(new IGeometryEntity[] { pt });
            }

            DSPlane plane = other as DSPlane;

            if (null != plane)
            {
                IPointEntity pt = plane.PlaneEntity.Project(PointEntity, dir);
                return(new IGeometryEntity[] { pt });
            }

            DSSolid solid = other as DSSolid;

            if (null != solid)
            {
                return(solid.SolidEntity.Project(PointEntity, dir));
            }

            return(base.ProjectOn(other, direction));
        }
Exemple #5
0
 protected DSCircle(DSPoint firstPoint, DSPoint secondPoint, DSVector normal, bool persist)
     : base(By2PointsCore(firstPoint, secondPoint, ref normal), persist)
 {
     InitializeGuaranteedProperties();
     FirstPoint  = firstPoint;
     SecondPoint = secondPoint;
 }
Exemple #6
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 #7
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 #8
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 DSPoint Project(DSPlane contextPlane, DSVector 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", "DSPoint.Project"));
            }

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

            pt.Context        = contextPlane;
            pt.ReferencePoint = this;
            pt.Direction      = direction;
            pt.Persist();
            return(pt);
        }
Exemple #9
0
 protected DSCircle(DSPoint firstPoint, DSPoint secondPoint, DSVector normal,bool persist)
     : base(By2PointsCore(firstPoint, secondPoint, ref normal),persist)
 {
     InitializeGuaranteedProperties();
     FirstPoint = firstPoint;
     SecondPoint = secondPoint;
 }
Exemple #10
0
        private DSPoint ProjectOnGeometry(DSGeometry contextGeometry, DSVector direction)
        {
            IPointEntity closestPoint = null;

            if (null == direction)
            {
                return(contextGeometry.ClosestPointTo(this));
            }
            else
            {
                IGeometryEntity[] entities = ProjectOn(contextGeometry, direction);
                if (null == entities || entities.Length == 0)
                {
                    throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "Project along direction"));
                }

                int             nearestIndex    = GetIndexOfNearestGeometry(entities, PointEntity);
                IGeometryEntity closestGeometry = entities[nearestIndex];
                //Clone the closest geometry
                closestPoint = closestGeometry.Clone() as IPointEntity;

                //Done with projected entities, dispose them.
                entities.DisposeObject();
            }

            return(new DSPoint(closestPoint, true));
        }
Exemple #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public double Dot(DSVector other)
 {
     if (other == null)
     {
         throw new System.ArgumentNullException("other");
     }
     return(X * other.X + Y * other.Y + Z * other.Z);
 }
Exemple #12
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 #13
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);
        }
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
        internal override IGeometryEntity[] ProjectOn(DSGeometry other, DSVector direction)
        {
            //Solid solid = other as Solid;
            //if (null != solid)
            //    return solid.SolidEntity.Project(SurfaceEntity, direction);

            return(base.ProjectOn(other, direction));
        }
Exemple #16
0
        private DSPlane Offset(DSVector offset)
        {
            IPointEntity origin    = Origin.PointEntity;
            IPointEntity newOrigin = origin.Add(offset);
            DSPlane      plane     = DSPlane.ByOriginNormal(newOrigin.ToPoint(false, null), Normal, Size);

            plane.Context = this;
            return(plane);
        }
Exemple #17
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 #18
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 #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public DSVector Cross(DSVector other)
 {
     if (other == null)
     {
         throw new System.ArgumentNullException("other");
     }
     return(DSVector.ByCoordinates(Y * other.Z - Z * other.Y,
                                   Z * other.X - X * other.Z,
                                   X * other.Y - Y * other.X));
 }
 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 #21
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;
 }
        protected override DSGeometry Translate(DSVector offset)
        {
            DSSubDivisionMesh mesh = base.Translate(offset) as DSSubDivisionMesh;

            if (null != mesh)
            {
                mesh.SubDivisionLevel = SubDivisionLevel;
            }

            return(mesh);
        }
Exemple #23
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);
     }
 }
 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 #25
0
        protected override DSGeometry Translate(DSVector offset)
        {
            IConeEntity clone = GeomEntity.CopyAndTranslate(offset.IVector) as IConeEntity;

            if (null == clone)
            {
                throw new System.InvalidOperationException("Failed to clone and translate geometry.");
            }

            return(new DSCone(clone, true));
        }
 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 #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public DSGeometry[] Project(DSGeometry other, DSVector direction)
        {
            if (null == other)
            {
                throw new ArgumentNullException("other");
            }

            IGeometryEntity[] geoms = null;
            geoms = other.ProjectOn(this, direction);

            return(geoms.ToArray <DSGeometry, IGeometryEntity>(true));
        }
Exemple #28
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 #29
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));
        }
Exemple #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        protected virtual DSGeometry Translate(DSVector offset)
        {
            IGeometryEntity clone = GeomEntity.CopyAndTranslate(offset.IVector);

            if (null == clone)
            {
                throw new InvalidOperationException("Failed to clone and translate geometry.");
            }

            DSGeometry geom = ToGeometry(clone, true);

            return(geom);
        }
Exemple #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="point"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public DSPoint Project(DSPoint point, DSVector 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));
        }
Exemple #32
0
        internal DSCoordinateSystem GetCSAtParameters(double u, double v)
        {
            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.PointAtUVParameters"));

            IPointEntity pos    = SurfaceEntity.PointAtParameter(u, v);
            DSPoint      origin = pos.ToPoint(false, null);
            DSVector     xAxis  = new DSVector(SurfaceEntity.TangentAtUParameter(u, v));
            DSVector     yAxis  = new DSVector(SurfaceEntity.TangentAtVParameter(u, v));
            DSVector     zAxis  = xAxis.Cross(yAxis);

            return(DSCoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis, false, true, false));
        }
Exemple #33
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);
        }
Exemple #34
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (Object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            DSVector vec = obj as DSVector;

            if (null == vec)
            {
                return(false);
            }

            return(DSGeometryExtension.Equals(vec.X, X) && DSGeometryExtension.Equals(vec.Y, Y) && DSGeometryExtension.Equals(vec.Z, Z));
        }
Exemple #35
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));
        }
        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;
        }
 /// <summary>
 /// Constructs a CoordinateSystem using origin point, X,Y and Z axis vectors, 'sheared' flag to determine if axes should be sheared or orthogonal and 'normalized' flag to normalize axes or not.
 /// </summary>
 /// <param name="origin">the origin of the CoordinateSystem to be constructed</param>
 /// <param name="xAxis">the x-axis of the CoordinateSystem to be constructed</param>
 /// <param name="yAxis">the y-axis of the CoordinateSystem to be constructed</param>
 /// <param name="zAxis">the z-axis of the CoordinateSystem to be constructed</param>
 /// <param name="isSheared">The 'sheared' flag is used to determine if the axes stay sheared or orthogonal to each other.</param>
 /// <param name="isNormalized">'normalized' flag is used to determine if axes should be normalized or not</param>
 /// <returns></returns>
 public static DSCoordinateSystem ByOriginVectors(DSPoint origin, DSVector xAxis, DSVector yAxis, DSVector zAxis, 
     bool isSheared, bool isNormalized)
 {
     return ByOriginVectors(origin, xAxis, yAxis, zAxis, isSheared, isNormalized, true);
 }
Exemple #38
0
        internal override IGeometryEntity[] ProjectOn(DSGeometry other, DSVector direction)
        {
            //Solid solid = other as Solid;
            //if (null != solid)
            //    return solid.SolidEntity.Project(SurfaceEntity, direction);

            return base.ProjectOn(other, direction);
        }
Exemple #39
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);
        }
Exemple #40
0
        internal DSCoordinateSystem GetCSAtParameters(double u, double v)
        {
            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.PointAtUVParameters"));

            IPointEntity pos = SurfaceEntity.PointAtParameter(u, v);
            DSPoint origin = pos.ToPoint(false, null);
            DSVector xAxis = new DSVector(SurfaceEntity.TangentAtUParameter(u, v));
            DSVector yAxis = new DSVector(SurfaceEntity.TangentAtVParameter(u, v));
            DSVector zAxis = xAxis.Cross(yAxis);

            return DSCoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis, false, true, false);
        }
Exemple #41
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);
 }
 /// <summary>
 /// Constructs a CoordinateSystem using an origin and 3 axes as input. 
 /// It assumes the axes to be normalized.
 /// </summary>
 /// <param name="origin">the origin of the CoordinateSystem to be constructed</param>
 /// <param name="xAxis">the x-axis of the CoordinateSystem to be constructed</param>
 /// <param name="yAxis">the y-axis of the CoordinateSystem to be constructed</param>
 /// <param name="zAxis">the z-axis of the CoordinateSystem to be constructed</param>
 /// <returns></returns>
 public static DSCoordinateSystem ByOriginVectors(DSPoint origin, DSVector xAxis, DSVector yAxis, DSVector zAxis)
 {
     return ByOriginVectors(origin, xAxis, yAxis, zAxis, false, true);
 }
Exemple #43
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 #44
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;
        }
Exemple #45
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 #46
0
        private static ICircleEntity By2PointsCore(DSPoint firstPoint, DSPoint secondPoint, ref DSVector 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 = DSCircle.ByCenterPointRadiusCore(centerPt, cptPos.DistanceTo(fptPos), ref normal);
            if (circleEntity == null)
                throw new Exception(string.Format(Properties.Resources.OperationFailed, "DSCircle.By2Points"));
            return circleEntity;
        }
Exemple #47
0
 protected DSCircle(DSPoint centerPoint, double radius, DSVector normal,bool persist)
     : base(ByCenterPointRadiusCore(centerPoint, radius, ref normal),persist)
 {
     InitializeGuaranteedProperties();
 }
        /// <summary>
        /// Constructor that does the same as CoordinateSystem.AtParameter but that it checks if the z-axis is
        /// in the same general direction as the given upVector. If not, it flips the z-axis to make it point 
        /// in the same overall direction as the upVector and also flips the y-axis accordingly to preserve 
        /// the right-handed CoordinateSystem rule.
        /// </summary>
        /// <param name="contextCurve"></param>
        /// <param name="t"></param>
        /// <param name="upVector"></param>
        /// <returns></returns>
        public static DSCoordinateSystem AtParameter(DSCurve contextCurve, double t, DSVector upVector)
        {
            if (contextCurve == null)
                throw new System.ArgumentNullException("contextCurve");
            else if (upVector == null)
                throw new System.ArgumentNullException("upVector");
            else if (upVector.IsZeroVector())
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "up vector"), "upVector");

            var cs = contextCurve.CoordinateSystemAtParameterCore(t, upVector);
            if (null == cs)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.AtParameter"));

            //  property assigments
            //
            cs.ContextCurve = contextCurve;
            cs.T = t;
            cs.Distance = contextCurve.DistanceAtParameter(t);
            cs.UpVector = upVector;

            return cs;
        }
 /// <summary>
 /// Translates the coordinate system by the coordinates specified
 /// </summary>
 /// <param name="xTranslation">Translation in the x direction</param>
 /// <param name="yTranslation">Translation in the y direction</param>
 /// <param name="zTranslation">Translation in the z direction</param>
 /// <returns></returns>
 public DSCoordinateSystem Translate(double xTranslation, double yTranslation, double zTranslation)
 {
     DSVector direction = new DSVector(xTranslation, yTranslation, zTranslation);
     return Translate(direction, direction.GetLength());
 }
        /// <summary>
        /// Constructs a CoordinateSystem from an origin point, and two axis 
        /// vectors as input. The 'sheared' flag is used to determine if the 
        /// axes stay sheared or orthogonal to each other and 'normalized' flag 
        /// to normalize axes or not.
        /// </summary>
        /// <param name="origin">the origin of the CoordinateSystem to be constructed</param>
        /// <param name="xAxis">the x-axis of the CoordinateSystem to be constructed</param>
        /// <param name="yAxis">the y-axis of the CoordinateSystem to be constructed</param>
        /// <param name="isSheared">The 'sheared' flag is used to determine if the 
        /// axes stay sheared or orthogonal to each other.</param>
        /// <param name="isNormalized">'normalized' flag is used to determine if axes 
        /// should be normalized or not</param>
        /// <returns></returns>
        public static DSCoordinateSystem ByOriginVectors(DSPoint origin, DSVector xAxis, DSVector yAxis, bool isSheared, bool isNormalized)
        {
            if (xAxis == null)
                throw new System.ArgumentNullException("xAxis");
            else if (yAxis == null)
                throw new System.ArgumentNullException("yAxis");
            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");

            var zAxis = xAxis.Cross(yAxis);
            return ByOriginVectors(origin, xAxis, yAxis, zAxis, isSheared, isNormalized);
        }
        /// <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;
        }
 /// <summary>
 /// Constructs a CoordinateSystem using an origin, three axes, and a flag to select whether to normalize the axes.
 /// </summary>
 /// <param name="origin">the origin of the CoordinateSystem to be constructed</param>
 /// <param name="xAxis">the x-axis of the CoordinateSystem to be constructed</param>
 /// <param name="yAxis">the y-axis of the CoordinateSystem to be constructed</param>
 /// <param name="zAxis">the z-axis of the CoordinateSystem to be constructed</param>
 /// <param name="normalized">flag to select whether to normalize the axes</param>
 /// <returns></returns>
 public static DSCoordinateSystem ByOriginVectors(DSPoint origin, DSVector xAxis, DSVector yAxis, DSVector zAxis, bool normalized)
 {
     return ByOriginVectors(origin, xAxis, yAxis, zAxis, false, normalized);
 }
Exemple #53
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 #54
0
 private void InitializeGuaranteedProperties()
 {
     Normal = new DSVector(CircleEntity.Normal);
     Radius = CircleEntity.Radius;
 }
 private void InitializeGuaranteedProperties()
 {
     XAxis = new DSVector(CSEntity.XAxis);
     YAxis = new DSVector(CSEntity.YAxis);
     ZAxis = new DSVector(CSEntity.ZAxis);
     Display = CSEntity.Display;
 }
Exemple #56
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 #57
0
 /// <summary>
 /// Constructs a circle passing 2 input points on diameter and using input vector as the normal.
 /// </summary>
 /// <param name="firstPoint">First point on the diameter</param>
 /// <param name="secondPoint">Second point on the diameter</param>
 /// <param name="normal">Normal to the plane of the circle</param>
 /// <returns></returns>
 public static DSCircle By2Points(DSPoint firstPoint, DSPoint secondPoint , DSVector normal )
 {
     return new DSCircle(firstPoint, secondPoint, normal, true);
 }
        /// <summary>
        /// Constructs a CoordinateSystem by transforming a parent CoordinateSystem, by a resultant transformation matrix of scaling [S], rotation [R] and transformation [T] matrices. 'translationSequence' = false implies [S][R][T] otherwise means [S][T][R].
        /// </summary>
        /// <param name="contextCoordinateSystem">the parent coordinate system to be used to construct the coordinate system</param>
        /// <param name="scaleFactors">the factor by which the parent coordinate system is to be scaled</param>
        /// <param name="rotationAngles">the rotation angle to be applied to the parent coordinate system</param>
        /// <param name="rotationSequence">the rotation sequence to be applied to the parent coordinate system</param>
        /// <param name="translationVector">the translation vector to be applied to the parent coordinate system</param>
        /// <param name="translationSequence">the translation sequence to be applied to the parent coordinate system</param>
        /// <returns></returns>
        public static DSCoordinateSystem ByUniversalTransform(DSCoordinateSystem contextCoordinateSystem, double[] scaleFactors, double[] rotationAngles,
            int[] rotationSequence, DSVector translationVector, bool translationSequence)
        {
            if (contextCoordinateSystem == null)
                throw new System.ArgumentNullException("contextCoordinateSystem");
            else if (scaleFactors == null)
                throw new System.ArgumentNullException("scaleFactors");
            else if (rotationAngles == null)
                throw new System.ArgumentNullException("rotationAngles");
            else if (rotationSequence == null)
                throw new System.ArgumentNullException("rotationSequence");
            else if (translationVector == null)
                throw new System.ArgumentNullException("translationVector");
            else if (scaleFactors.Length < 3)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of scale factors", "three"), "scaleFactors");
            else if (rotationAngles.Length < 3)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of rotation angles", "three"), "rotationAngles");
            else if (rotationSequence.Length < 3)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of rotation sequences", "three"), "rotationSequence");

            using (var localCSEntity = HostFactory.Factory.CoordinateSystemByUniversalTransform(contextCoordinateSystem.CSEntity, scaleFactors,
                                            rotationAngles, rotationSequence, translationVector.IVector, translationSequence))
            {
                if (null == localCSEntity)
                    throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.ByUniversalTransform"));

                var cs = CreateCoordinateSystem(contextCoordinateSystem, localCSEntity, true);
                cs.ScaleFactors = scaleFactors;
                cs.RotationAngles = rotationAngles;
                cs.RotationSequence = rotationSequence;
                cs.TranslationVector = translationVector;
                cs.TranslationSequence = translationSequence;

                return cs;
            }
        }
Exemple #59
0
        protected override DSGeometry Translate(DSVector offset)
        {
            IConeEntity clone = GeomEntity.CopyAndTranslate(offset.IVector) as IConeEntity;
            if (null == clone)
                throw new System.InvalidOperationException("Failed to clone and translate geometry.");

            return new DSCone(clone, true);
        }
Exemple #60
0
 /// <summary>
 /// Constructs a circle from its center point and radius with given vector
 /// </summary>
 /// <param name="centerPoint">The desired center point of the circle</param>
 /// <param name="radius">The desired radius of the circle</param>
 /// <param name="normal">Normal to the plane of the surface</param>
 /// <returns></returns>
 public static DSCircle ByCenterPointRadius(DSPoint centerPoint, double radius, DSVector normal)
 {
     return new DSCircle(centerPoint, radius, normal, true);
 }