def __getitem__(self, index): try: u, v = index except TypeError: return self.points[index] else: pnt = self.occ_surface.Pole(u + 1, v + 1) return Point.from_occ(pnt)
def aabb(self, precision=0.0, optimal=False): """Compute the axis aligned bounding box of the surface. Parameters ---------- precision : float, optional optimal : bool, optional Returns ------- :class:`~compas.geometry.Box` """ box = Bnd_Box() if optimal: add = BndLib_AddSurface_AddOptimal else: add = BndLib_AddSurface_Add add(GeomAdaptor_Surface(self.occ_surface), precision, box) return Box.from_diagonal( (Point.from_occ(box.CornerMin()), Point.from_occ(box.CornerMax())))
def point_at(self, u, v): """Compute a point on the surface. Parameters ---------- u : float v : float Returns ------- :class:`~compas.geometry.Point` """ point = self.occ_surface.Value(u, v) return Point.from_occ(point)
def frame_at(self, u, v): """Compute the local frame at a point on the curve. Parameters ---------- u : float v : float Returns ------- :class:`~compas.geometry.Frame` """ point = gp_Pnt() uvec = gp_Vec() vvec = gp_Vec() self.occ_surface.D1(u, v, point, uvec, vvec) return Frame(Point.from_occ(point), Vector.from_occ(uvec), Vector.from_occ(vvec))
def curvature_at(self, u, v): """Compute the curvature at a point on the surface. Parameters ---------- u : float v : float Returns ------- :class:`~compas.geometry.Vector` """ props = GeomLProp_SLProps(self.occ_surface, u, v, 2, 1e-6) gaussian = props.GaussianCurvature() mean = props.MeanCurvature() point = props.Value() normal = props.Normal() return gaussian, mean, Point.from_occ(point), Vector.from_occ(normal)
def intersections_with_line(self, line): """Compute the intersections with a line. Parameters ---------- line : :class:`~compas.geometry.Line` Returns ------- list[:class:`~compas.geometry.Point`] """ intersection = GeomAPI_IntCS(Geom_Line(line.to_occ()), self.occ_surface) points = [] for index in range(intersection.NbPoints()): pnt = intersection.Point(index + 1) point = Point.from_occ(pnt) points.append(point) return points
def closest_point(self, point, return_parameters=False): """Compute the closest point on the curve to a given point. Parameters ---------- point : Point The point to project to the surface. return_parameters : bool, optional If True, return the surface UV parameters in addition to the closest point. Returns ------- :class:`~compas.geometry.Point` | tuple[:class:`~compas.geometry.Point`, tuple[float, float]] If `return_parameters` is False, the nearest point on the surface. If `return_parameters` is True, the UV parameters in addition to the nearest point on the surface. """ projector = GeomAPI_ProjectPointOnSurf(point.to_occ(), self.occ_surface) point = Point.from_occ(projector.NearestPoint()) if not return_parameters: return point return point, projector.LowerDistanceParameters()
points2.append(Point(2, 3, -1)) points2.append(Point(3, 7, -2)) points2.append(Point(4, 9, -1)) spline2 = BSplineCurve.from_points(points2) surface = BSplineSurface.from_fill(spline1, spline2) line = Geom_Line(gp_Pnt(0, 4, 0), gp_Dir(0, 0, 1)) # ============================================================================== # Intersection # ============================================================================== intersection = GeomAPI_IntCS(line, surface.occ_surface) pnt = intersection.Point(1) point = Point.from_occ(pnt) # ============================================================================== # Viz # ============================================================================== mesh = surface.to_vizmesh() boundary = Polyline( mesh.vertices_attributes('xyz', keys=mesh.vertices_on_boundary())) view = App() view.add(mesh) view.add(boundary, linewidth=2) view.add(point, size=10, color=(1, 0, 0)) view.run()