/// <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); }
/// <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); }
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); }
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); }
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); }
/// <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)); }
/// <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)); }
/// <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 DSPoint Project(DSSolid contextSolid, DSVector 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"); } DSPoint pt = ProjectOnGeometry(contextSolid, direction); pt.Context = contextSolid; pt.Direction = direction; pt.ReferencePoint = this; return(pt); }
/// <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()); } } } } }
/// <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 DSPoint Project(DSCurve curve, DSVector 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); }
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); }
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); }
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); }
/// <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; }
/// <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); }
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; }
/// <summary> /// Projects the given point along the given direction onto this curve /// </summary> /// <param name="point">Point for projection</param> /// <param name="direction">Direction for projection</param> /// <returns>Project point on curve</returns> internal DSPoint Project(DSPoint point, DSVector direction) { string kMethodName = "DSCurve.Project"; if (point == null) throw new System.ArgumentNullException("point"); else if (direction == null) throw new System.ArgumentNullException("direction"); else if (direction.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, direction), "direction"); IPointEntity projectedPt = CurveEntity.Project(point.PointEntity, direction.IVector); if (projectedPt == null) throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); return projectedPt.ToPoint(true, this); }
/// <summary> /// def RevolveAsSurface : Surface (axisOrigin : Point, axisDirection : Vector, startAngle : double, sweepAngle : double) /// /// Returns a Surface by revolving this curve about an axis defined by /// axisOrigin point and axisDirection Vector. startAngle determines /// where the curve starts to revolve, sweepAngle determines the /// revolving angle. /// </summary> /// <param name="axisOrigin">Origin point of axis of revolution</param> /// <param name="axisDirection">Direction vector of axis of revolution</param> /// <param name="startAngle">Start angle in degrees</param> /// <param name="sweepAngle">Sweep angle for rotation in degrees</param> /// <returns>Revolved Surface</returns> public DSSurface RevolveAsSurface(DSPoint axisOrigin, DSVector axisDirection, double startAngle, double sweepAngle) { if (axisOrigin == null) throw new System.ArgumentNullException("axisOrigin"); else if (axisDirection == null) throw new System.ArgumentNullException("axisDirection"); else if (axisDirection.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, axisDirection), "axisDirection"); else if (sweepAngle.EqualsTo(0.0)) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroAngle, "sweep"), "sweepAngle"); return DSSurface.Revolve(this, axisOrigin, axisDirection, startAngle, sweepAngle); }
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; }
/// <summary> /// Rotates the input CoordinateSystem about its own axes and about the global origin (0,0,0) by the given rotation angles /// in the given rotation sequence. The rotation angles are always specified in the order of rotation about (xAxis, yAxis, zAxis). /// </summary> /// <param name="rotationAngle">The angle to be rotated through</param> /// <param name="axis">The axis to be rotated about</param> /// <param name="origin">The global origin</param> /// <returns>Returns a rotated CoordinateSystem</returns> public DSCoordinateSystem Rotate(double rotationAngle, DSVector axis, DSPoint origin) { if (axis == null) throw new System.ArgumentNullException("axis"); else if (origin == null) throw new System.ArgumentNullException("origin"); else if (axis.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "axis"), "axis"); var rotatedCSEntity = CSEntity.Rotation(rotationAngle, axis.IVector, origin.PointEntity); var cs = new DSCoordinateSystem(rotatedCSEntity, true); return cs; }
/// <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> /// def RevolveAsSolid : Solid (axisOrigin : Point, axisDirection : Vector) /// /// Returns a Solid by revolving close curve about an axis defined by /// axisOrigin point and axisDirection Vector. Assuming sweep angle = 360 /// and start angle = 0. /// </summary> /// <param name="axisOrigin">Origin point of axis of revolution</param> /// <param name="axisDirection">Direction vector of axis of revolution</param> /// <returns>Revolved Solid</returns> public DSSolid RevolveAsSolid(DSPoint axisOrigin, DSVector axisDirection) { if (axisOrigin == null) throw new System.ArgumentNullException("axisOrigin"); else if (axisDirection == null) throw new System.ArgumentNullException("axisDirection"); else if (!IsClosed) throw new System.InvalidOperationException(Properties.Resources.CurveNotClosed); else if (!IsPlanar) throw new System.InvalidOperationException(Properties.Resources.CurveNotPlanar); else if (axisDirection.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, axisDirection), "axisDirection"); return DSSolid.Revolve(this, axisOrigin, axisDirection); }
/// <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 DSPoint Project(DSCurve curve, DSVector 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; }
/// <summary> /// def RevolveAsSurface(axisOrigin : Point, axisDirection : Vector) /// /// Returns a Surface by revolving this curve about an axis defined by /// axisOrigin point and axisDirection Vector. Assuming sweep angle = 360 /// and start angle = 0. /// </summary> /// <param name="axisOrigin">Origin Point of axis of revolution</param> /// <param name="axisDirection">Direction Vector of axis of revolution</param> /// <returns>Revolved Surface</returns> public DSSurface RevolveAsSurface(DSPoint axisOrigin, DSVector axisDirection) { if (axisOrigin == null) throw new System.ArgumentNullException("axisOrigin"); else if (axisDirection == null) throw new System.ArgumentNullException("axisDirection"); else if (axisDirection.IsZeroVector()) throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, axisDirection), "axisDirection"); return DSSurface.Revolve(this, axisOrigin, axisDirection); }
/// <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; }
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 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 DSPoint Project(DSSolid contextSolid, DSVector 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"); DSPoint pt = ProjectOnGeometry(contextSolid, direction); pt.Context = contextSolid; pt.Direction = direction; pt.ReferencePoint = this; return pt; }
/// <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); }
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; }
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; }
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; }
/// <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); }
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; }