-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating an ellipse mesh produces spurious points #44
Comments
This was a problem that I encountered semi-recently. I found a workaround that produced a mesh that still was not very good, but was better for my application. This mesh, above, is created using a constant angular spacing of nodes initially, essentially you are meshing in polar coordinates. This is why it bunches up in places. If you can eliminate that problem then creating a more usable mesh is easier. To do this you need to use the pseudo-angle from the elliptical coordinate system. Then you mesh initially over the rectangular in elliptical coordinates domain, then you can convert the mesh to the cartesian coordinate system.
Gives. Note the displaced spurious points shown up close here. |
Many thanks. |
I have thought a bit more about this problem and come up with a solution that generates almost equidistance points around an ellipse, and then uses the polygon mesh feature in # Generate equidistance (almost) points around the periphery of an ellipse
# Ref: https://stackoverflow.com/questions/44334655/how-to-divide-circumference-of-an-ellipse-equally?noredirect=1&lq=1
# Note: A more exact procedure is possible using 'elliptic integrals'. Finding
# the true value for the perimiter is straight forward using python
# function ellipe and is included as a check. However, a full calculation
# requires obtaining inverse elliptic integrals and I have not yet found
# a way yet. So have abandoned this for now., see:
# Ref: https://math.stackexchange.com/questions/172766/calculating-equidistant-points-around-an-ellipse-arc
import numpy as np
from scipy.special import ellipe # complete elliptic integral of the second type
import matplotlib.pyplot as plt
def distance(x1,y1,x2,y2):
return np.sqrt((x2-x1)**2 + (y2-y1)**2)
a = 10 #5
b = 4 #3
m = 1-b**2/a**2 # eccentricity of ellipse
da = 4*a*ellipe(m) # analytical value for ellipse perimiter
x0 = a
y0 = 0
angle = 0
d = 0
del_a = 2*np.pi/10000
while(angle<=2*np.pi):
x = a * np.cos(angle)
y = b * np.sin(angle)
d += distance(x0,y0,x,y)
x0 = x
y0 = y
angle += del_a
print( "Circumference of ellipse: numeric = %f, analytic = %f" %(d,da))
N = 17
h = d/N
angle = 0
x0 = a
y0 = 0
angle0 = 0
xx = np.zeros(N)
yy = np.zeros(N)
for i in range(N):
dist = 0
while(dist<h):
x = a * np.cos(angle)
y = b * np.sin(angle)
dist += distance(x0,y0,x,y)
x0 = x
y0 = y
angle += del_a
xx[i] = x
yy[i] = y
# generate analytical points on ellipse
N1 = 50
aa = np.linspace(0,2*np.pi,N1)
xa = a*np.cos(aa)
ya = b*np.sin(aa)
# plt.figure()
# plt.subplot(211)
# plt.plot(xa,ya,"b-")
# plt.plot(xx,yy,'r.')
# =================
# Use dmsh to generate mesh from polygon
import dmsh
import optimesh
# ellipse data as a polygon with N1 points
dat = [[xa[0],ya[0]]]
for i in range(1,N1-1) :
dat.append([xa[i],ya[i]])
geo = dmsh.Polygon(dat)
#plt.subplot(212)
X, cells = dmsh.generate(geo, 0.5)
# optionally optimize the mesh
import optimesh
X, cells = optimesh.optimize_points_cells(X, cells, "CVT (full)", 1.0e-10, 100)
# visualize the mesh
dmsh.helpers.show(X, cells, geo, full_screen=False) |
I have now managed to come up with a solution that generates equidistance points around an ellipse using elliptic functions, which then uses the polygon mesh feature in
|
Creating an ellipse generates spurious points on the periphery. Windows 10, python 3.8.3, Anaconda.
The text was updated successfully, but these errors were encountered: