Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions physicsnemo/sym/geometry/primitives_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
)
from functools import reduce

pi = float(pi)
from sympy.vector import CoordSys3D

from .curve import SympyCurve
from .helper import _sympy_sdf_to_sdf
from .geometry import Geometry, csg_curve_naming
from .parameterization import Parameterization, Parameter, Bounds
from .helper import _sympy_sdf_to_sdf
from .parameterization import Bounds, Parameter, Parameterization

pi = float(pi)


class Line(Geometry):
Expand All @@ -64,19 +66,19 @@ def __init__(self, point_1, point_2, normal=1, parameterization=Parameterization
assert point_1[0] == point_2[0], "Points must have same x-coordinate"

# make sympy symbols to use
l = Symbol(csg_curve_naming(0))
t = Symbol(csg_curve_naming(0))
x = Symbol("x")

# curves for each side
curve_parameterization = Parameterization({l: (0, 1)})
curve_parameterization = Parameterization({t: (0, 1)})
curve_parameterization = Parameterization.combine(
curve_parameterization, parameterization
)
dist_y = point_2[1] - point_1[1]
line_1 = SympyCurve(
functions={
"x": point_1[0],
"y": point_1[1] + l * dist_y,
"y": point_1[1] + t * dist_y,
"normal_x": 1e-10 + normal, # TODO rm 1e-10
"normal_y": 0,
},
Expand Down Expand Up @@ -135,19 +137,19 @@ class Channel2D(Geometry):

def __init__(self, point_1, point_2, parameterization=Parameterization()):
# make sympy symbols to use
l = Symbol(csg_curve_naming(0))
t = Symbol(csg_curve_naming(0))
y = Symbol("y")

# curves for each side
curve_parameterization = Parameterization({l: (0, 1)})
curve_parameterization = Parameterization({t: (0, 1)})
curve_parameterization = Parameterization.combine(
curve_parameterization, parameterization
)
dist_x = point_2[0] - point_1[0]
dist_y = point_2[1] - point_1[1]
line_1 = SympyCurve(
functions={
"x": l * dist_x + point_1[0],
"x": t * dist_x + point_1[0],
"y": point_1[1],
"normal_x": 0,
"normal_y": -1,
Expand All @@ -157,7 +159,7 @@ def __init__(self, point_1, point_2, parameterization=Parameterization()):
)
line_2 = SympyCurve(
functions={
"x": l * dist_x + point_1[0],
"x": t * dist_x + point_1[0],
"y": point_2[1],
"normal_x": 0,
"normal_y": 1,
Expand Down Expand Up @@ -209,19 +211,19 @@ class Rectangle(Geometry):

def __init__(self, point_1, point_2, parameterization=Parameterization()):
# make sympy symbols to use
l = Symbol(csg_curve_naming(0))
t = Symbol(csg_curve_naming(0))
x, y = Symbol("x"), Symbol("y")

# curves for each side
curve_parameterization = Parameterization({l: (0, 1)})
curve_parameterization = Parameterization({t: (0, 1)})
curve_parameterization = Parameterization.combine(
curve_parameterization, parameterization
)
dist_x = point_2[0] - point_1[0]
dist_y = point_2[1] - point_1[1]
line_1 = SympyCurve(
functions={
"x": l * dist_x + point_1[0],
"x": t * dist_x + point_1[0],
"y": point_1[1],
"normal_x": 0,
"normal_y": -1,
Expand All @@ -232,7 +234,7 @@ def __init__(self, point_1, point_2, parameterization=Parameterization()):
line_2 = SympyCurve(
functions={
"x": point_2[0],
"y": l * dist_y + point_1[1],
"y": t * dist_y + point_1[1],
"normal_x": 1,
"normal_y": 0,
},
Expand All @@ -241,7 +243,7 @@ def __init__(self, point_1, point_2, parameterization=Parameterization()):
)
line_3 = SympyCurve(
functions={
"x": l * dist_x + point_1[0],
"x": t * dist_x + point_1[0],
"y": point_2[1],
"normal_x": 0,
"normal_y": 1,
Expand All @@ -252,7 +254,7 @@ def __init__(self, point_1, point_2, parameterization=Parameterization()):
line_4 = SympyCurve(
functions={
"x": point_1[0],
"y": -l * dist_y + point_2[1],
"y": -t * dist_y + point_2[1],
"normal_x": -1,
"normal_y": 0,
},
Expand Down Expand Up @@ -370,10 +372,10 @@ def __init__(self, center, base, height, parameterization=Parameterization()):

N = CoordSys3D("N")
P = x * N.i + y * N.j
O = center[0] * N.i + center[1] * N.j
origin = center[0] * N.i + center[1] * N.j
H = center[0] * N.i + (center[1] + height) * N.j
OP = P - O
OH = H - O
OP = P - origin
OH = H - origin
PH = OH - OP
angle = acos(PH.dot(OH) / sqrt(PH.dot(PH)) / sqrt(OH.dot(OH)))
apex_angle = atan2(base / 2, height)
Expand Down Expand Up @@ -450,8 +452,10 @@ class Ellipse(Geometry):
----------
center : tuple with 2 ints or floats
center point of circle
radius : int or float
radius of circle
major : int or float
major axis of ellipse
minor : int or float
minor axis of ellipse
parameterization : Parameterization
Parameterization of geometry.
"""
Expand All @@ -466,7 +470,7 @@ def __init__(self, center, major, minor, parameterization=Parameterization()):
)
try:
area = float(area)
except:
except (TypeError, ValueError):
pass

# curve for perimeter of the circle
Expand Down
1 change: 1 addition & 0 deletions physicsnemo/sym/hydra/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def compose(
register_scheduler_configs()
register_training_configs()
register_physicsnemo_configs()
register_amp_configs()
register_graph_configs()

cfg = hydra.compose(
Expand Down
2 changes: 1 addition & 1 deletion physicsnemo/sym/utils/io/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __call__(self, invar, outvar):
for k in outvar:
f = plt.figure(figsize=(5, 4), dpi=100)
if ndim == 1:
plt.plot(invar[dims[0]][:, 0], outvar[:, 0])
plt.plot(invar[dims[0]][:, 0], outvar[k][:, 0])
plt.xlabel(dims[0])
elif ndim == 2:
plt.imshow(outvar[k].T, origin="lower", extent=extent)
Expand Down