def project_vertex(self, pnt_or_vertex): ''' returns the closest orthogonal project on `pnt` on edge ''' if isinstance(pnt_or_vertex, TopoDS_Vertex): pnt_or_vertex = vertex2pnt(pnt_or_vertex) poc = GeomAPI_ProjectPointOnCurve(pnt_or_vertex, self.curve_handle) return poc.LowerDistanceParameter(), poc.NearestPoint()
def fit_plane_through_face_vertices(_face): """ :param _face: OCC.KBE.face.Face instance :return: Geom_Plane """ from OCC.GeomPlate import GeomPlate_BuildAveragePlane uvs_from_vertices = [_face.project_vertex(vertex2pnt(i)) for i in Topo(_face).vertices()] normals = [gp_Vec(_face.DiffGeom.normal(*uv[0])) for uv in uvs_from_vertices] points = [i[1] for i in uvs_from_vertices] NORMALS = TColgp_SequenceOfVec() [NORMALS.Append(i) for i in normals] POINTS = to_tcol_(points, TColgp_HArray1OfPnt) pl = GeomPlate_BuildAveragePlane(NORMALS, POINTS).Plane().GetObject() vec = gp_Vec(pl.Location(), _face.GlobalProperties.centre()) pt = (pl.Location().as_vec() + vec).as_pnt() pl.SetLocation(pt) return pl
def fit_plane_through_face_vertices(_face): """ :param _face: OCC.KBE.face.Face instance :return: Geom_Plane """ from OCC.Core.GeomPlate import GeomPlate_BuildAveragePlane uvs_from_vertices = [ _face.project_vertex(vertex2pnt(i)) for i in Topo(_face).vertices() ] normals = [ gp_Vec(_face.DiffGeom.normal(*uv[0])) for uv in uvs_from_vertices ] points = [i[1] for i in uvs_from_vertices] NORMALS = TColgp_SequenceOfVec() [NORMALS.Append(i) for i in normals] POINTS = to_tcol_(points, TColgp_HArray1OfPnt) pl = GeomPlate_BuildAveragePlane(NORMALS, POINTS).Plane().GetObject() vec = gp_Vec(pl.Location(), _face.GlobalProperties.centre()) pt = (pl.Location().as_vec() + vec).as_pnt() pl.SetLocation(pt) return pl