meshpro/dmsh

Could this generate mesh on an arbitrary contour?

Closed this issue · 4 comments

For example, I have a boundary of an arbitrary shape on an image. It could not be parameterized by your function

How about a polygon?

Closing for lack of feedback. Feel free to reopen at any time.

Just wanted to note that you can do this for any contour, first by making an arbitrary function that outputs an array of [x,y] coordinates associated with the edges.

for a quarter ellipse...

import numpy as np

#This is in polar coordinates to generate equi-theta spaced points. Can do it in elliptical or whatever.

def EllipsePol(a,b,Points):
    theta=np.linspace(0,np.pi/2,Points)
    r = a*b/np.sqrt((b**2 -a**2)*np.cos(theta)**2 + a**2)
    theta=np.append(theta,0)
    r=np.append(r,0)
    return np.array([r,theta])

#Converts to Cartesian

def PolToCart(r,theta):
    x=r*np.cos(theta)
    y=r*np.sin(theta)    
    return np.array([x,y])

#Define A and B and resolution (How polygon-esque it is)
A=2
B=5
res=5

Points=PolToCart(EllipsePol(A,B,res)[0],EllipsePol(A,B,res)[1])
geo = dmsh.Polygon(Points.T)
X, cells = dmsh.generate(geo,.3)
dmsh.helpers.show(X, cells, geo)

yields

image

With a high resolution:
image

The weird elements are due to the spacing of the poly-points. See with equi-X spacing:

image

The weird boundary on ellipse meshes are a known bug, see #44.