protected DSText(DSCoordinateSystem contextCoordinateSystem, Orientation orientation, string textString, double fontSize,bool persist) : base(ByCoordinateSystemCore(contextCoordinateSystem, orientation, textString, fontSize),persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; Orientation = orientation; }
protected DSPoint(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double phi,bool persist, int unused) : base(BySphericalCoordinatesCore(contextCoordinateSystem, radius, theta, phi),persist) { InitializeGuaranteedProperties(); Radius = radius; Theta = theta; Phi = phi; }
protected DSCylinder(DSCoordinateSystem contextCoordinateSystem, double radius, double height,bool persist) : base(CylinderByRadiusHeightCore(contextCoordinateSystem.CSEntity, radius, height),persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; Radius = radius; Height = height; }
protected DSPoint(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double height,bool persist,bool unused) : base(ByCylindricalCoordinatesCore(contextCoordinateSystem, radius, theta, height),true) { InitializeGuaranteedProperties(); Radius = radius; Theta = theta; Height = height; }
protected DSPoint(DSCoordinateSystem contextCoordinateSystem, double xTranslation, double yTranslation, double zTranslation,bool persist) : base(ByCartesianCoordinatesCore(contextCoordinateSystem,xTranslation,yTranslation,zTranslation),persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; XTranslation = xTranslation; YTranslation = yTranslation; ZTranslation = zTranslation; }
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); }
/// <summary> /// Scales the given CoordinateSystem by a non-uniform scaling factor along each axis /// </summary> /// <param name="scaleX"></param> /// <param name="scaleY"></param> /// <param name="scaleZ"></param> /// <returns></returns> public DSCoordinateSystem Scale(double scaleX, double scaleY, double scaleZ) { if (DSGeometryExtension.Equals(scaleX, 0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "scale x"), "scaleX"); } else if (DSGeometryExtension.Equals(scaleY, 0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "scale y"), "scaleY"); } else if (DSGeometryExtension.Equals(scaleZ, 0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "scale z"), "scaleZ"); } var scaledCsEntity = CSEntity.Scale(scaleX, scaleY, scaleZ); var cs = new DSCoordinateSystem(scaledCsEntity, true); return cs; }
/// <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; }
private static IConeEntity ByRadiusHeightCore(DSCoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height) { string kMethod = "DSCone.ByRadiusHeight"; if (startRadius.LessThanOrEqualTo(0.0)) throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "start radius"), "startRadius"); if (endRadius < 0.0) throw new System.ArgumentException(string.Format(Properties.Resources.LessThanZero, "end radius"), "endRadius"); if (height.LessThanOrEqualTo(0.0)) throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "height"), "height"); if (null == contextCoordinateSystem) throw new System.ArgumentNullException("contextCoordinateSystem"); if (!contextCoordinateSystem.IsUniscaledOrtho()) { if (contextCoordinateSystem.IsScaledOrtho()) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "Non Uniform Scaled DSCoordinateSystem", kMethod)); else throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "Shear DSCoordinateSystem", kMethod)); } IConeEntity entity = HostFactory.Factory.ConeByRadiusLength(contextCoordinateSystem.CSEntity, startRadius, endRadius, height); if (null == entity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethod)); return entity; }
/// <summary> /// /// </summary> /// <returns></returns> public static DSCoordinateSystem Identity() { var cs = HostFactory.Factory.CoordinateSystemByData(null); //create identity matrix if (null == cs) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.Identity")); DSCoordinateSystem coordSys = new DSCoordinateSystem(cs, true); coordSys.IsNormalized = true; return coordSys; }
/// <summary> /// Constructs a CoordinateSystem by transforming a parent CoordinateSystem, by a resultant transformation matrix of scaling [S], rotation [R] and transformation [T] matrices in the order [S][R][T]. /// </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> /// <returns></returns> public static DSCoordinateSystem ByUniversalTransform(DSCoordinateSystem contextCoordinateSystem, double[] scaleFactors, double[] rotationAngles, int[] rotationSequence, double[] translationVector) { return ByUniversalTransform(contextCoordinateSystem, scaleFactors, rotationAngles, rotationSequence, translationVector, false); }
private static DSCoordinateSystem CreateCoordinateSystem(DSCoordinateSystem contextCoordinateSystem, ICoordinateSystemEntity localCoordSys, bool visible) { ICoordinateSystemEntity csEntity = contextCoordinateSystem.CSEntity.PostMultiplyBy(localCoordSys); var cs = new DSCoordinateSystem(csEntity, visible); cs.ContextCoordinateSystem = contextCoordinateSystem; cs.LocalXAxis = new DSVector(localCoordSys.XAxis); cs.LocalYAxis = new DSVector(localCoordSys.YAxis); cs.LocalZAxis = new DSVector(localCoordSys.ZAxis); cs.XTranslation = localCoordSys.Origin.X; cs.YTranslation = localCoordSys.Origin.Y; cs.ZTranslation = localCoordSys.Origin.Z; return cs; }
/// <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> /// Constructors a point based on the spherical CoordinateSystem. /// </summary> /// <param name="contextCoordinateSystem">The coordinate system</param> /// <param name="radius">The radius of the sphere</param> /// <param name="theta">The theta value of the sphere</param> /// <param name="phi">The phi value of the sphere</param> /// <returns></returns> public static DSPoint BySphericalCoordinates(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double phi) { return new DSPoint(contextCoordinateSystem, radius, theta, phi, true, 1); }
/// <summary> /// Constructors a point based on the cylindrical CoordinateSystem. /// </summary> /// <param name="contextCoordinateSystem">The coordinate system</param> /// <param name="radius">The radius of the cylinder</param> /// <param name="theta">The theta of the cylinder</param> /// <param name="height">The height of the cylinder</param> /// <returns></returns> public static DSPoint ByCylindricalCoordinates(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double height) { return new DSPoint(contextCoordinateSystem, radius, theta, height, true, true); }
/// <summary> /// Constructors a point based on the Cartesian CoordinateSystem. /// </summary> /// <param name="contextCoordinateSystem">The coordinate system with respect to which the x,y,z translation are given</param> /// <param name="xTranslation">Translation in the x direction with respect to context coordinate system</param> /// <param name="yTranslation">Translation in the y direction with respect to context coordinate system</param> /// <param name="zTranslation">Translation in the z direction with respect to context coordinate system</param> /// <returns></returns> public static DSPoint ByCartesianCoordinates(DSCoordinateSystem contextCoordinateSystem, double xTranslation, double yTranslation, double zTranslation) { return new DSPoint(contextCoordinateSystem, xTranslation, yTranslation, zTranslation, true); }
internal DSBlockInstance(DSCoordinateSystem contextCoordinateSystem, string blockName, bool persist) : base(DSBlock.InsertCore(contextCoordinateSystem, blockName),persist) { Definition = new DSBlock(blockName); ContextCoordinateSystem = contextCoordinateSystem; }
internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, string blockName) { string kMethodName = "DSBlock.ByCoordinateSystem "; if (null == contextCoordinateSystem) throw new ArgumentNullException("contextCoordinateSystem"); if (contextCoordinateSystem.IsSheared) throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem"); if (string.IsNullOrEmpty(blockName)) throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName"); IBlockHelper helper = HostFactory.Factory.GetBlockHelper(); if (null == helper) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); if (!helper.BlockExistsInCurrentDocument(blockName)) throw new System.ArgumentException(string.Format(Properties.Resources.DoesNotExist, "DSBlock : " + blockName)); IBlockEntity entity = helper.InsertBlockFromCurrentDocument(contextCoordinateSystem.CSEntity, blockName); if (null == entity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName)); return entity; }
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; }
private static IPointEntity ByCartesianCoordinatesCore(DSCoordinateSystem contextCoordinateSystem, double xTranslation, double yTranslation, double zTranslation) { if (contextCoordinateSystem == null) { return ByCoordinatesCore(xTranslation, yTranslation, zTranslation); } IPointEntity pos = HostFactory.Factory.PointByCartesianCoordinates(contextCoordinateSystem.CSEntity, xTranslation, yTranslation, zTranslation); if (pos == null) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSPoint.ByCartesianCoordinates")); return pos; }
/// <summary> /// Constructs a CoordinateSystem where the x-axis of the CoordinateSystem is tangential to the sphere along the /// latitudinal direction, the z-axis is normal to the spherical surface and the y-axis is along the longitudinal /// direction at the point defined on the sphere by the r, theta, phi values. /// </summary> /// <param name="contextCoordinateSystem"> /// the parent coordinate system to be used to construct the coordinate system /// </param> /// <param name="radius"> /// the radius of the spherical surface /// </param> /// <param name="theta"> /// the theta value of the spherical surface /// </param> /// <param name="phi"> /// the phi value of the spherical surface /// </param> /// <returns> /// CoordinateSystem created in Spherical world /// </returns> public static DSCoordinateSystem BySphericalCoordinates(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double phi) { // what can be the constraints on theta if (contextCoordinateSystem == null) throw new System.ArgumentNullException("contextCoordinateSystem "); else if (radius.EqualsTo(0.0)) throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "radius"), "radius"); using (var localCSEntity = HostFactory.Factory.CoordinateSystemBySphericalCoordinates(WCS.CSEntity, radius, theta, phi)) { if (null == localCSEntity) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.BySphericalCoordinates")); var cylCS = CreateCoordinateSystem(contextCoordinateSystem, localCSEntity, true); cylCS.Radius = radius; cylCS.Theta = theta; cylCS.Phi = phi; return cylCS; } }
private static IPointEntity BySphericalCoordinatesCore(DSCoordinateSystem contextCoordinateSystem, double radius, double theta, double phi) { if (contextCoordinateSystem == null) { throw new ArgumentNullException(string.Format("contextCoordinateSystem")); } else if (radius == 0.0) { throw new ArgumentException(Properties.Resources.IsZeroRadius); } using (var csEntity = HostFactory.Factory.CoordinateSystemBySphericalCoordinates(DSCoordinateSystem.WCS.CSEntity, radius, theta, phi)) { IPointEntity origin = csEntity.Origin; IPointEntity pt = ByCartesianCoordinatesCore(contextCoordinateSystem, origin.X, origin.Y, origin.Z); if (null == pt) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSPoint.BySphericalCoordinates")); return pt; } }
/// <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; } }
private static DSPlane FromCoordinateSystem(DSCoordinateSystem cs) { if (null == cs) return null; DSPlane plane = DSPlane.ByOriginNormal(cs.Origin, cs.ZAxis); if (null == plane) return null; plane.ContextCoordinateSystem = cs; return plane; }
/// <summary> /// Inverts the transformation matrix of the current CoordinateSystem and returns a CoordinateSystem /// </summary> /// <returns>Returns inverted CoordinateSystem</returns> public DSCoordinateSystem Inverse() { ICoordinateSystemEntity invertedMat = CSEntity.Inverse(); if (null == invertedMat) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.Inverse")); var cs = new DSCoordinateSystem(invertedMat, true); return cs; }
/// <summary><para> /// Returns an array of uniformly scaled orthogonal coordinate system /// located on the curve with equal distance. The X axis is the tangent /// at the point, The Y axis is the Normal at the point. </para><para> /// When Z axis is in the opposite direction of upVector, the coordinate /// system will be flipped so that the resultant Z axis is in the same /// direction as the upVector. The Y-axis will also be flipped so that /// it maintains the right-handed coordinate system rule.</para> /// <para> Argument Requirement: /// numberOfPoints > 0 </para> /// </summary> /// <param name="numberOfCoordinateSystems"></param> /// <param name="upVector"></param> /// <returns></returns> public DSCoordinateSystem[] CoordinateSystemsAtEqualArcLength(int numberOfCoordinateSystems, DSVector upVector) { if (numberOfCoordinateSystems < 1) throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of coordinateSystems", "one"), "numberOfCoordinateSystems"); IPointEntity[] pts = PointsAtEqualArcLengthCore(numberOfCoordinateSystems); if (null == pts) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "number of coordinateSystems"), "numberOfCoordinateSystems"); DSCoordinateSystem[] css = new DSCoordinateSystem[pts.Length]; int i = 0; foreach (var p in pts) { double param = CurveEntity.ParameterAtPoint(p); try { css[i++] = DSCoordinateSystem.AtParameter(this, param, upVector); } catch { //Proceed with next iteration. } p.Dispose(); } return css; }
/// <summary> /// Constructs a solid cone defined a parent CoordinateSystem, start radius, end radius and height /// </summary> /// <param name="contextCoordinateSystem">The parent CoordinateSystem of the cone</param> /// <param name="startRadius">The radius of the base of the cone</param> /// <param name="endRadius">The radius of the top of the cone</param> /// <param name="height">The height of the cone</param> /// <returns></returns> public static DSCone ByRadiusHeight(DSCoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height) { return new DSCone(contextCoordinateSystem, startRadius, endRadius, height, true); }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <returns></returns> public DSCoordinateSystem Multiply(DSCoordinateSystem other) { if (other == null) throw new System.ArgumentNullException("other"); ICoordinateSystemEntity resultantMat = CSEntity.PostMultiplyBy(other.CSEntity); if (resultantMat == null) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.Multiply")); return new DSCoordinateSystem(resultantMat, true); }
protected DSCone(DSCoordinateSystem contextCoordinateSystem, double startRadius, double endRadius, double height, bool persist) : base(ByRadiusHeightCore(contextCoordinateSystem, startRadius, endRadius, height), persist) { InitializeGuaranteedProperties(); ContextCoordinateSystem = contextCoordinateSystem; }
/// <summary> /// /// </summary> /// <param name="leftSide"></param> /// <returns></returns> public DSCoordinateSystem PreMultiplyBy(DSCoordinateSystem leftSide) { if (leftSide == null) throw new System.ArgumentNullException("leftSide"); ICoordinateSystemEntity resultantMat = CSEntity.PreMultiplyBy(leftSide.CSEntity); if (null == resultantMat) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.PreMultiplyBy")); return new DSCoordinateSystem(resultantMat, true); }