-
Notifications
You must be signed in to change notification settings - Fork 0
/
ray_trace_curvature.1.py
187 lines (161 loc) · 5.7 KB
/
ray_trace_curvature.1.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import numpy as np
import matplotlib.pyplot as plt
import json
import glob
import sys
import time
import os
import scipy.constants as cnt
from unwrap.unwrap import unwrap
from mpl_toolkits.axes_grid1 import make_axes_locatable
from linecache import getline, clearcache
from scipy.integrate import simps
from optparse import OptionParser
sys.path.append(os.path.join('../'))
from src.RayTrace.RaySystem import RaySystem, SurfSystem, OptSystem, Multi_RaySystem
from src.RayTrace.ray_setup import get_axs, get_deg, axs_pln
from src.Unit import convert_SI, convert
from src.geomtory import curvature
from src.pyocc.surface import surf_spl, curv_spl
from OCCUtils.Topology import Topo
from OCCUtils.Construct import project_edge_onto_plane, project_point_on_curve
from OCCUtils.Construct import make_wire, make_edge, make_plane, make_line, make_loft
from OCCUtils.Construct import dir_to_vec, vec_to_dir
from OCC.BRep import BRep_Tool, BRep_PointsOnSurface
from OCC.BRep import BRep_ListNodeOfListOfPointRepresentation
from OCC.TopLoc import TopLoc_Location
from OCC.TopoDS import TopoDS_Face
from OCC.GeomLProp import GeomLProp_SurfaceTool, GeomLProp_SLProps
from OCC.GeomAbs import GeomAbs_C2, GeomAbs_C0, GeomAbs_G1, GeomAbs_G2
from OCC.GeomAPI import GeomAPI_ProjectPointOnSurf, GeomAPI_ProjectPointOnCurve
from OCC.GeomAPI import GeomAPI_PointsToBSplineSurface, GeomAPI_IntCS
from OCC.GeomAPI import GeomAPI_ExtremaCurveCurve, GeomAPI_Interpolate
from OCC.TColgp import TColgp_Array1OfPnt, TColgp_Array2OfPnt
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeFace
from OCC.BRepBuilderAPI import BRepBuilderAPI_ParametersOutOfRange
from OCC.Geom import Geom_Curve, Geom_Line, Geom_Ellipse
from OCC.Geom import Geom_Plane, Geom_Surface, Geom_BSplineSurface, Geom_BSplineCurve
from OCC.Geom import Geom_ConicalSurface, Geom_Conic
from OCC.gp import gp_Pln, gp_Trsf, gp_Lin, gp_Elips, gp_Elips2d
from OCC.gp import gp_Pnt, gp_Vec, gp_Dir, gp_Ax1, gp_Ax2, gp_Ax3
from OCC.gp import gp_Mat
from OCC.Display.SimpleGui import init_display
def wavefront(rxy=[1000, 1000], axs=gp_Ax3()):
px = np.linspace(-1, 1, 100) * 10
py = np.linspace(-1, 1, 100) * 10
mesh = np.meshgrid(px, py)
rx_0 = curvature(mesh[0], rxy[0], 0)
ry_0 = curvature(mesh[1], rxy[1], 0)
ph_0 = rx_0 + ry_0
phas = surf_spl(*mesh, ph_0)
trf = gp_Trsf()
trf.SetTransformation(axs, gp_Ax3())
loc_face = TopLoc_Location(trf)
phas.Location(loc_face)
return phas
def wavefront_xyz(x, y, z, axs=gp_Ax3()):
phas = surf_spl(x, y, z)
trf = gp_Trsf()
trf.SetTransformation(axs, gp_Ax3())
loc_face = TopLoc_Location(trf)
phas.Location(loc_face)
return phas
def second_derivative(h_surf, u=0, v=0):
p1 = gp_Pnt()
pu, pv = gp_Vec(), gp_Vec()
puu, pvv = gp_Vec(), gp_Vec()
puv = gp_Vec()
prop = GeomLProp_SLProps(h_surf, u, v, 1, 1)
GeomLProp_SurfaceTool.D2(h_surf, u, v, p1, pu, pv, puu, pvv, puv)
e0 = pu.Crossed(pv)
pu.Normalize()
pv.Normalize()
e0.Normalize()
puu.Normalize()
pvv.Normalize()
puv.Normalize()
print(p1)
print("pu", pu)
print("pv", pv)
print("e0", e0)
print("puu", puu)
print("pvv", pvv)
print("puv", puv)
first_form = np.array([
[pu.Dot(pu), pu.Dot(pv)],
[pv.Dot(pu), pv.Dot(pv)]
])
secnd_form = np.array([
[e0.Dot(puu), e0.Dot(puv)],
[e0.Dot(puv), e0.Dot(pvv)]
])
print(first_form)
print(secnd_form)
print(prop.GaussianCurvature())
print(prop.MeanCurvature())
d1, d2 = gp_Dir(), gp_Dir()
prop.CurvatureDirections(d1, d2)
a1 = gp_Ax3()
v1 = dir_to_vec(d1)
v2 = dir_to_vec(d2)
if pu.IsParallel(v1, 1 / 1000):
c1 = prop.MaxCurvature()
c2 = prop.MinCurvature()
print(v1.Dot(pu), v1.Dot(pv))
print(v2.Dot(pu), v2.Dot(pv))
else:
c1 = prop.MinCurvature()
c2 = prop.MaxCurvature()
print(v1.Dot(pu), v1.Dot(pv))
print(v2.Dot(pu), v2.Dot(pv))
print(c1, 1 / c1)
print(c2, 1 / c2)
px = np.linspace(-1, 1, 100) * 100
p1_y = px**2 / c1
p2_y = px**2 / c1
curv1 = curv_spl(px, p1_y)
curv2 = curv_spl(px, p2_y)
if __name__ == "__main__":
argvs = sys.argv
parser = OptionParser()
parser.add_option("--dir", dest="dir", default="./")
opt, argc = parser.parse_args(argvs)
print(argc, opt)
display, start_display, add_menu, add_function_to_menu = init_display()
axs = gp_Ax3()
deg = 30
rad = 0
obj = Geom_ConicalSurface(axs, np.deg2rad(deg), rad)
surf = BRepBuilderAPI_MakeFace(
obj.GetHandle(), -np.pi / 2, np.pi / 2, -100, 100, 1e-6).Face()
display.DisplayShape(surf)
display.DisplayShape(obj)
display.DisplayShape(axs_pln(axs))
display.FitAll()
start_display()
init = "surf1"
surf = ["surf2", "surf3", "surf4"]
surf1 = SurfSystem("./", "surf1")
surf2 = SurfSystem("./", "surf2")
h_surf = BRep_Tool.Surface(surf1.srf)
second_derivative(h_surf, 0.5, 0.5)
second_derivative(h_surf, 0.5, 0.0)
second_derivative(h_surf, 0.0, 0.5)
"""h_surf = BRep_Tool.Surface(surf2.srf)
second_derivative(h_surf, 0.5, 0.5)
second_derivative(h_surf, 0.5, 0.0)
second_derivative(h_surf, 0.0, 0.5)
second_derivative(h_surf, 0.0, 0.0)"""
"""print(surf1.name, surf1.axs.Location())
print(surf2.name, surf2.axs.Location())
print(surf2.srf)
loc_surf = surf2.srf
loc_trsf = gp_Trsf()
loc_trsf.SetTransformation(gp_Ax3(), surf2.axs)
loc_face = TopLoc_Location(loc_trsf)
loc_surf.Move(loc_face)
h_surf = BRep_Tool.Surface(loc_surf)
second_derivative(h_surf, 0.5, 0.5)
#second_derivative(h_surf, 1.0, 0)
h_surf = BRep_Tool.Surface(surf2.srf)
second_derivative(h_surf, 0.5, 0.5)"""