Skip to content

Commit

Permalink
Merge branch 'csg2d_trig_ellipse' into 'master'
Browse files Browse the repository at this point in the history
add triangle and ellipse as csg2d solid objects

See merge request jschoeberl/netgen!347
  • Loading branch information
mhochsteger committed Nov 11, 2020
2 parents de76069 + 870b147 commit 6b5ba0b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions python/geom2d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .libngpy._geom2d import SplineGeometry, Solid2d, CSG2d, Rectangle, Circle, EdgeInfo, PointInfo
from .meshing import meshsize
import math as math

unit_square = SplineGeometry()
_pnts = [ (0,0), (1,0), (1,1), (0,1) ]
Expand Down Expand Up @@ -144,3 +145,34 @@ def cp(p_or_px, py_or_none = None):
return EdgeInfo(control_point=p)
else:
return EdgeInfo(control_point=(p_or_px,py_or_none))


def Ellipse(center, a, b, bc="ellipse", mat="ellipse"):
"""Creates ellipse centered at point center with principle axis a and b.
Parameters
---------
center : Vec2
center of ellipse
a : Vec2
first principle axis, needs to be perpendicular to b
b : Vec2
second principle axis, needs to be perpendicular to a
bc : string
boundary name
mat : string
material name
"""
if abs(a[0]*b[0] + a[1]*b[1]) > 1e-12:
raise Exception("In Ellipse: principle axis a and b are not perpendicular")

ellipse = Circle( center=(0,0), radius=1.0, mat=mat, bc=bc )

alpha = math.pi/2-math.atan2(a[0],a[1])
r_a = math.sqrt(a[0]**2+a[1]**2)
r_b = math.sqrt(b[0]**2+b[1]**2)
ellipse.Scale( (r_a,r_b) )
ellipse.Rotate( alpha/math.pi*180, center=(0,0) )
ellipse.Move( center )

return ellipse

0 comments on commit 6b5ba0b

Please sign in to comment.