/// <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 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)); }
/// <summary> /// Constructors a plane on a surface by given parameter. /// </summary> /// <param name="contextSurface"></param> /// <param name="u"></param> /// <param name="v"></param> /// <returns></returns> public static DSPlane AtParameter(DSSurface contextSurface, double u, double v) { DSCoordinateSystem cs = DSCoordinateSystem.AtParameterCore(contextSurface, u, v, false); DSPlane plane = DSPlane.FromCoordinateSystem(cs); plane.Context = contextSurface; plane.U = u; plane.V = v; return(plane); }
/// <summary> /// /// </summary> /// <param name="surface"></param> /// <param name="selectPoint"></param> /// <param name="autoExtend"></param> /// <returns></returns> public DSSurface Trim(DSSurface surface, DSPoint selectPoint, bool autoExtend) { if (null == surface) { throw new System.ArgumentNullException("surface"); } DSSurface[] surfaces = { surface }; return(Trim(null, null, surfaces, null, selectPoint, autoExtend)); }
/// <summary> /// Split this surface using a surface as cutting tool. /// </summary> /// <param name="splittingSurface">Surface as cutting tool.</param> /// <returns>Array of surfaces.</returns> public DSSurface[] Split(DSSurface splittingSurface) { ISurfaceEntity[] splitSurfaces = SurfaceEntity.Split(splittingSurface.SurfaceEntity); if (null == splitSurfaces || splitSurfaces.Length < 1) { throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSSurface.Split")); } return(splitSurfaces.ConvertAll((ISurfaceEntity host) => host.ToSurf(true, this))); }
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); }
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); }
public DSGeometry[] Intersect(DSGeometry other) { if (null == other) { throw new ArgumentNullException("other"); } IGeometryEntity[] geoms = null; DSPlane plane = other as DSPlane; if (plane != null) { geoms = IntersectWithPlane(plane); } else { DSSurface surf = other as DSSurface; if (surf != null) { geoms = IntersectWithSurface(surf); } else { DSSolid solid = other as DSSolid; if (solid != null) { geoms = IntersectWithSolid(solid); } else { DSCurve curve = other as DSCurve; if (curve != null) { geoms = IntersectWithCurve(curve); } else { DSPoint point = other as DSPoint; if (null != point) { geoms = IntersectWithPoint(point); } else { throw new System.InvalidOperationException(string.Format(Properties.Resources.InvalidIntersect, GetType().Name, other.GetType().Name)); } } } } } return(geoms.ToArray <DSGeometry, IGeometryEntity>(true)); }
/// <summary> /// Returns a parallel Surface with specific distance from original surface. /// </summary> /// <param name="distance">Offset distance value.</param> /// <returns>Surface.</returns> public DSSurface Offset(double distance) { if (distance.EqualsTo(0.0)) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "offset distance"), "distance"); } ISurfaceEntity surfEntity = SurfaceEntity.Offset(distance); if (null == surfEntity) { throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSSurface.Offset")); } DSSurface surf = surfEntity.ToSurf(true, this); surf.Context = this; return(surf); }
/// <summary> /// Contructs a point on the normal of a given surface at a given offset /// </summary> /// <param name="contextSurface">Input surface</param> /// <param name="u">U parameter value</param> /// <param name="v">V parameter value</param> /// <param name="offset">Offset in the direction of normal</param> /// <returns>Point</returns> internal static DSPoint AtParameter(DSSurface contextSurface, double u, double v, double offset) { if (contextSurface == null) { return(null); } var pt = contextSurface.PointAtParametersCore(ref u, ref v, offset); if (null == pt) { return(null); } pt.Context = contextSurface; pt.U = u; pt.V = v; pt.Distance = offset; pt.Persist(); return(pt); }
public DSSolid[] Slice(DSSurface surface, bool isRegular) { if (null == surface) { throw new ArgumentNullException("surface"); } IGeometryEntity[] solids = null; if (isRegular) { solids = SolidEntity.SliceWithSurface(surface.SurfaceEntity); } else { solids = new[] { SolidEntity.NonRegularSliceWithSurface(surface.SurfaceEntity) } }; if (solids == null || solids.Length == 0) { throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSSolid.Slice")); } return(solids.ToArray <DSSolid, IGeometryEntity>(true)); }
/// <summary> /// /// </summary> /// <param name="contextSurface"></param> /// <param name="u"></param> /// <param name="v"></param> /// <returns></returns> public static DSSurfaceCurvature BySurfaceParameters(DSSurface contextSurface, double u, double v) { if (contextSurface == null) { return(null); } ISurfaceEntity host = contextSurface.GetSurfaceEntity(); if (host == null) { return(null); } ICoordinateSystemEntity coordinateSystemEntity = host.CurvatureAtParameter(u, v); if (null != coordinateSystemEntity) { DSSurfaceCurvature surfCurv = new DSSurfaceCurvature(contextSurface, u, v, coordinateSystemEntity); return(surfCurv); } return(null); }
/// <summary> /// Constructs a point by projecting a point on surface. It is equivalent /// to finding the nearest point on the surface /// </summary> /// <param name="contextSurface">The surface on which the projection is to be made.</param> /// <returns>Projected point on surface</returns> public DSPoint Project(DSSurface contextSurface) { if (null == contextSurface) { throw new ArgumentNullException("contextSurface"); } DSPoint pt = ProjectOnGeometry(contextSurface, null); if (null == pt) { throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "Project on surface")); } pt.Context = contextSurface; pt.ReferencePoint = this; double[] parameters = contextSurface.ParameterAtPoint(pt); if (null != parameters) { pt.U = parameters[0]; pt.V = parameters[1]; } return(pt); }
/// <summary> /// /// </summary> /// <param name="curves"></param> /// <param name="planes"></param> /// <param name="surfaces"></param> /// <param name="solids"></param> /// <param name="selectPoint"></param> /// <param name="autoExtend"></param> /// <returns></returns> public DSSurface Trim(DSCurve[] curves, DSPlane[] planes, DSSurface[] surfaces, DSSolid[] solids, DSPoint selectPoint, bool autoExtend) { if (null == selectPoint) throw new System.ArgumentNullException("selectPoint"); ICurveEntity[] hostCurves = curves.ConvertAll(DSGeometryExtension.ToEntity<DSCurve, ICurveEntity>); IPlaneEntity[] hostPlanes = planes.ConvertAll(DSGeometryExtension.ToEntity<DSPlane, IPlaneEntity>); ISurfaceEntity[] hostSurfaces = surfaces.ConvertAll(DSGeometryExtension.ToEntity<DSSurface, ISurfaceEntity>); ISolidEntity[] hostSolids = solids.ConvertAll(DSGeometryExtension.ToEntity<DSSolid, ISolidEntity>); IPointEntity hostPoint = selectPoint.PointEntity; if (hostCurves == null && hostPlanes == null && hostSurfaces == null && hostSolids == null) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "DSGeometry", "DSSurface.Trim")); ISurfaceEntity trimSurface = SurfaceEntity.Trim(hostCurves, hostPlanes, hostSurfaces, hostSolids, hostPoint, autoExtend); //For trim operation, if the return value is not null, hide the original tools and surfaces. if (null != trimSurface) { Hide(curves); Hide(planes); Hide(surfaces); Hide(solids); SetVisibility(false); } return trimSurface.ToSurf(true, this); }
public static DSSurface[] SelectTrim(DSSurface[] surfaces, DSSolid[] trimmingSolids, bool keepInside) { string kMethodName = "DSSurface.SelectTrim"; ISurfaceEntity[] surfacehosts = surfaces.ConvertAll(DSGeometryExtension.ToEntity<DSSurface, ISurfaceEntity>); if (surfacehosts == null || surfacehosts.Length == 0) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "surfaces", kMethodName), "surfaces"); ISolidEntity[] solidhosts = trimmingSolids.ConvertAll(DSGeometryExtension.ToEntity<DSSolid, ISolidEntity>); if (null == solidhosts || solidhosts.Length == 0) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "trimmingSolids", kMethodName), "trimmingSolids"); DSSurface[] result = null; if (solidhosts.Length == 1) { result = SelectTrimCore(surfacehosts, solidhosts[0], keepInside); } else { DSSolid unionSolid = DSSolid.UnionCore(solidhosts[0], solidhosts, false); if (null == unionSolid) throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); result = SelectTrimCore(surfacehosts, unionSolid.SolidEntity, keepInside); } if (null != result) { Hide(surfaces); Hide(trimmingSolids); } return result; }
/// <summary> /// Split this surface using a surface as cutting tool. /// </summary> /// <param name="splittingSurface">Surface as cutting tool.</param> /// <returns>Array of surfaces.</returns> public DSSurface[] Split(DSSurface splittingSurface) { ISurfaceEntity[] splitSurfaces = SurfaceEntity.Split(splittingSurface.SurfaceEntity); if (null == splitSurfaces || splitSurfaces.Length < 1) { throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSSurface.Split")); } return splitSurfaces.ConvertAll((ISurfaceEntity host) => host.ToSurf(true, this)); }
/// <summary> /// /// </summary> /// <param name="surface"></param> /// <param name="selectPoint"></param> /// <returns></returns> public DSSolid Trim(DSSurface surface, DSPoint selectPoint) { DSSurface[] surfaces = { surface }; return(Trim(null, surfaces, null, selectPoint)); }
public static DSSurface[] SelectTrim(DSSurface[] surfaces, DSSolid trimmingSolid, bool keepInside) { string kMethodName = "DSSurface.SelectTrim"; if (null == trimmingSolid) throw new System.ArgumentNullException("trimmingSolid"); ISurfaceEntity[] surfacehosts = surfaces.ConvertAll(DSGeometryExtension.ToEntity<DSSurface, ISurfaceEntity>); if (surfacehosts == null || surfacehosts.Length == 0) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "surfaces", kMethodName), "surfaces"); ISolidEntity trimmingEntity = trimmingSolid.SolidEntity; DSSurface[] result = SelectTrimCore(surfacehosts, trimmingEntity, keepInside); if (null != result) { Hide(surfaces); Hide(trimmingSolid); } return result; }
/// <summary> /// Constructs a point by projecting a point on surface. It is equivalent /// to finding the nearest point on the surface /// </summary> /// <param name="contextSurface">The surface on which the projection is to be made.</param> /// <returns>Projected point on surface</returns> public DSPoint Project(DSSurface contextSurface) { if (null == contextSurface) throw new ArgumentNullException("contextSurface"); DSPoint pt = ProjectOnGeometry(contextSurface, null); if (null == pt) throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "Project on surface")); pt.Context = contextSurface; pt.ReferencePoint = this; double[] parameters = contextSurface.ParameterAtPoint(pt); if (null != parameters) { pt.U = parameters[0]; pt.V = parameters[1]; } return pt; }
/// <summary> /// Contructs a point on a given surface at given U, V parameter. /// </summary> /// <param name="contextSurface">Input Surface</param> /// <param name="u">U parameter value.</param> /// <param name="v">V parameter value.</param> /// <returns>Point</returns> public static DSPoint AtParameter(DSSurface contextSurface, double u, double v) { return AtParameter(contextSurface, u, v, 0.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; }
/// <summary> /// /// </summary> /// <param name="contextSurface"></param> /// <param name="u"></param> /// <param name="v"></param> /// <returns></returns> public static DSSurfaceCurvature BySurfaceParameters(DSSurface contextSurface, double u, double v) { if (contextSurface == null) return null; ISurfaceEntity host = contextSurface.GetSurfaceEntity(); if (host == null) return null; ICoordinateSystemEntity coordinateSystemEntity = host.CurvatureAtParameter(u, v); if (null != coordinateSystemEntity) { DSSurfaceCurvature surfCurv = new DSSurfaceCurvature(contextSurface, u, v, coordinateSystemEntity); return surfCurv; } return null; }
/// <summary> /// Constructors a plane on a surface by given parameter. /// </summary> /// <param name="contextSurface"></param> /// <param name="u"></param> /// <param name="v"></param> /// <returns></returns> public static DSPlane AtParameter(DSSurface contextSurface, double u, double v) { DSCoordinateSystem cs = DSCoordinateSystem.AtParameterCore(contextSurface, u, v, false); DSPlane plane = DSPlane.FromCoordinateSystem(cs); plane.Context = contextSurface; plane.U = u; plane.V = v; return plane; }
/// <summary> /// Contructs a point on the normal of a given surface at a given offset /// </summary> /// <param name="contextSurface">Input surface</param> /// <param name="u">U parameter value</param> /// <param name="v">V parameter value</param> /// <param name="offset">Offset in the direction of normal</param> /// <returns>Point</returns> internal static DSPoint AtParameter(DSSurface contextSurface, double u, double v, double offset) { if (contextSurface == null) return null; var pt = contextSurface.PointAtParametersCore(ref u, ref v, offset); if (null == pt) return null; pt.Context = contextSurface; pt.U = u; pt.V = v; pt.Distance = offset; pt.Persist(); return pt; }
/// <summary> /// /// </summary> /// <param name="surfaces"></param> /// <param name="selectPoint"></param> /// <param name="autoExtend"></param> /// <returns></returns> public DSSurface Trim(DSSurface[] surfaces, DSPoint selectPoint, bool autoExtend) { if(null == surfaces) throw new System.ArgumentNullException("surfaces"); return Trim(null, null, surfaces, null, selectPoint, autoExtend); }
// TODO: To be fixed - pratapa /// <summary> /// /// </summary> /// <param name="planes"></param> /// <param name="surfaces"></param> /// <param name="solids"></param> /// <param name="selectPoint"></param> /// <returns></returns> public DSSolid Trim(DSPlane[] planes, DSSurface[] surfaces, DSSolid[] solids, DSPoint selectPoint) { IPlaneEntity[] hostPlanes = planes.ConvertAll(DSGeometryExtension.ToEntity<DSPlane, IPlaneEntity>); ISurfaceEntity[] hostSurfaces = surfaces.ConvertAll(DSGeometryExtension.ToEntity<DSSurface, ISurfaceEntity>); ISolidEntity[] hostSolids = solids.ConvertAll(DSGeometryExtension.ToEntity<DSSolid, ISolidEntity>); if (selectPoint == null) throw new System.ArgumentNullException("selectPoint"); IPointEntity hostPoint = selectPoint.PointEntity; if (hostPlanes == null && hostSurfaces == null && hostSolids == null) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "DSGeometry", "DSSolid.Trim")); ISolidEntity trimSolid = SolidEntity.Trim(hostPlanes, hostSurfaces, hostSolids, hostPoint); if (null == trimSolid) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSSolid.Trim")); Hide(planes); Hide(surfaces); Hide(solids); SetVisibility(false); return new DSSolid(trimSolid, true); }
public DSSolid[] Slice(DSSurface surface, bool isRegular) { if (null == surface) throw new ArgumentNullException("surface"); IGeometryEntity[] solids = null; if (isRegular) solids = SolidEntity.SliceWithSurface(surface.SurfaceEntity); else solids = new[] { SolidEntity.NonRegularSliceWithSurface(surface.SurfaceEntity) }; if (solids == null || solids.Length == 0) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSSolid.Slice")); return solids.ToArray<DSSolid, IGeometryEntity>(true); }
public DSSolid[] Slice(DSSurface[] surfaces, bool isRegular) { ISurfaceEntity[] surfaceHosts = surfaces.ConvertAll(DSGeometryExtension.ToEntity<DSSurface, ISurfaceEntity>); if (null == surfaceHosts || surfaceHosts.Length == 0) throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "surfaces", "DSSolid.Slice"), "surfaces"); IGeometryEntity[] solids = null; if (isRegular) solids = SolidEntity.SliceWithSurfaces(surfaceHosts); else solids = new[] { SolidEntity.NonRegularSliceWithSurfaces(surfaceHosts) }; if (solids == null || solids.Length == 0) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSSolid.Slice")); return solids.ToArray<DSSolid, IGeometryEntity>(true); }
internal override IGeometryEntity[] IntersectWithSurface(DSSurface surf) { throw new System.InvalidOperationException(string.Format(Properties.Resources.InvalidIntersect, GetType().Name, "DSSurface")); }
internal override IGeometryEntity[] IntersectWithSurface(DSSurface surf) { return SurfaceEntity.IntersectWith(surf.SurfaceEntity); }
/// <summary> /// Contructs a point on a given surface at given U, V parameter. /// </summary> /// <param name="contextSurface">Input Surface</param> /// <param name="u">U parameter value.</param> /// <param name="v">V parameter value.</param> /// <returns>Point</returns> public static DSPoint AtParameter(DSSurface contextSurface, double u, double v) { return(AtParameter(contextSurface, u, v, 0.0)); }
internal override IGeometryEntity[] IntersectWithSurface(DSSurface surf) { throw new System.InvalidOperationException(string.Format(Properties.Resources.InvalidIntersect, GetType().Name, "DSSurface")); }
internal static DSCoordinateSystem AtParameterCore(DSSurface contextSurface, double u, double v, bool visible) { if (contextSurface == null) throw new System.ArgumentNullException("contextSurface"); var cs = contextSurface.GetCSAtParameters(u, v); if (null == cs) throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSCoordinateSystem.AtParameter")); cs.ContextSurface = contextSurface; cs.U = u; cs.V = v; cs.Visible = visible; return cs; }
/// <summary> /// /// </summary> /// <param name="surfaces"></param> /// <param name="selectPoint"></param> /// <returns></returns> public DSSolid Trim(DSSurface[] surfaces, DSPoint selectPoint) { return Trim(null, surfaces, null, selectPoint); }
/// <summary> /// Constructs a CoordinateSystem at the given u, v parameters on the given surface. The x-axis of the CoordinateSystem /// is aligned with the u-directional tangent, the y-axis with the v-directional tangent and the z-axis is mutually /// perpendicular to the x and y axes. /// </summary> /// <param name="contextSurface"></param> /// <param name="u"></param> /// <param name="v"></param> /// <returns></returns> public static DSCoordinateSystem AtParameter(DSSurface contextSurface, double u, double v) { return AtParameterCore(contextSurface, u, v, true);//make sure it's visible }
internal override IGeometryEntity[] IntersectWithSurface(DSSurface surf) { return(SurfaceEntity.IntersectWith(surf.SurfaceEntity)); }
public DSCurve[] Project(DSSurface surface, DSVector direction) { string kMethodName = "DSCurve.Project"; if (null == surface) throw new System.ArgumentNullException("surface"); else if (null == direction) throw new System.ArgumentNullException("direction"); IGeometryEntity[] entities = CurveEntity.ProjectOn(surface.SurfaceEntity, direction.IVector); if(null == entities) throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName)); return entities.ToArray<DSCurve, IGeometryEntity>(true); }