-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPolygon.py
More file actions
106 lines (85 loc) · 3.3 KB
/
Polygon.py
File metadata and controls
106 lines (85 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
from OCC.Core.BRepBuilderAPI import (BRepBuilderAPI_MakeFace,
BRepBuilderAPI_MakePolygon,
BRepBuilderAPI_MakeShell,
BRepBuilderAPI_MakeSolid)
from OCC.Core.GeomAPI import GeomAPI_Interpolate, GeomAPI_PointsToBSpline
from OCC.Core.GeomLib import GeomLib_Interpolate
from OCC.Core.Geom import Geom_BSplineCurve
from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3, gp_Dir, gp_Pnt, gp_Vec
from OCC.Core.TColgp import TColgp_Array1OfPnt, TColgp_HArray1OfPnt
from OCC.Core.TColStd import TColStd_Array1OfReal
from OCCUtils.Construct import make_edge, make_face, make_polygon
from scipy.spatial import ConvexHull
from base import plotocc
""" Spatial Transformations
.. autosummary::
:toctree: generated/
KDTree -- class for efficient nearest-neighbor queries
cKDTree -- class for efficient nearest-neighbor queries (faster impl.)
Rectangle
"""
""" Delaunay Triangulation, Convex Hulls and Voronoi Diagrams
.. autosummary::
:toctree: generated/
Delaunay -- compute Delaunay triangulation of input points
ConvexHull -- compute a convex hull for input points
Voronoi -- compute a Voronoi diagram hull from input points
SphericalVoronoi -- compute a Voronoi diagram from input points on the surface of a sphere
HalfspaceIntersection -- compute the intersection points of input halfspaces
"""
class GenPolygon (plotocc):
def __init__(self):
plotocc.__init__(self)
self.gen_area(num=20)
print(self.cov)
for idx in self.cov.simplices:
self.tri_plane(idx)
for i, xyz in enumerate(self.pnt):
p = gp_Pnt(*xyz)
self.display.DisplayShape(p)
p0 = gp_Pnt(*self.pnt[0])
p1 = gp_Pnt(*self.pnt[1])
p2 = gp_Pnt(*self.pnt[2])
p3 = gp_Pnt(*self.pnt[3])
poly = make_polygon([p0, p1, p2, p3], closed=True)
#face = make_face(poly)
# self.display.DisplayShape(poly)
self.tri_curve()
def gen_area(self, num=10):
self.pnt = np.random.rand(num, 3)
self.cov = ConvexHull(self.pnt[:, 0:3])
def tri_plane(self, idx=[0, 1, 2]):
p0 = gp_Pnt(*self.pnt[idx[0]])
p1 = gp_Pnt(*self.pnt[idx[1]])
p2 = gp_Pnt(*self.pnt[idx[2]])
poly = make_polygon([p0, p1, p2], closed=True)
face = make_face(poly)
print(idx, poly, face)
self.display.DisplayShape(face, transparency=0.7, color="BLUE")
def tri_curve(self, idx=[0, 1, 2]):
p0 = gp_Pnt(*self.pnt[idx[0]])
p1 = gp_Pnt(*self.pnt[idx[1]])
p2 = gp_Pnt(*self.pnt[idx[2]])
#pts = TColgp_Array1OfPnt(1, 5)
pts = TColgp_Array1OfPnt(1, 4)
pts.SetValue(1, p0)
pts.SetValue(2, p1)
pts.SetValue(3, p2)
pts.SetValue(4, p0)
#pts.SetValue(5, p1)
wgt = TColStd_Array1OfReal(1, 4)
wgt.SetValue(1, 0)
wgt.SetValue(2, 0)
wgt.SetValue(3, 0)
wgt.SetValue(4, 0)
api = GeomLib_Interpolate(0, 4, pts, wgt)
crv = api.Curve()
print(crv)
# self.display.DisplayShape(crv)
if __name__ == '__main__':
obj = GenPolygon()
obj.show_axs_pln(scale=0.5)
obj.show()