mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
csg2d - fix tutorial
This commit is contained in:
parent
10a9decfd2
commit
2763285b46
@ -345,12 +345,35 @@ bool IsOverlapping( Spline p, Spline s, double & alpha, double & beta, Intersect
|
|||||||
// Check if s.p0 lies on p and vice versa, also check if tangents are in same direction (TODO: TEST)
|
// Check if s.p0 lies on p and vice versa, also check if tangents are in same direction (TODO: TEST)
|
||||||
// If so, assume overlapping splines
|
// If so, assume overlapping splines
|
||||||
// TODO: Better checks! False positives could happen here!
|
// TODO: Better checks! False positives could happen here!
|
||||||
IntersectSplineSegment1( p, s.StartPI(), p_mid, lam0, alpha, true );
|
if(Dist(s.StartPI(), p.StartPI())<EPSILON)
|
||||||
IntersectSplineSegment1( s, p.StartPI(), s_mid, lam1, beta, true );
|
{
|
||||||
|
lam0 = 0.0;
|
||||||
|
alpha = 0.0;
|
||||||
|
}
|
||||||
|
else if(Dist(s.StartPI(), p.EndPI())<EPSILON)
|
||||||
|
{
|
||||||
|
lam0 = 0.0;
|
||||||
|
alpha = 1.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
IntersectSplineSegment1( p, s.StartPI(), p_mid, lam0, alpha, true );
|
||||||
|
|
||||||
|
if(Dist(p.StartPI(), s.StartPI())<EPSILON)
|
||||||
|
{
|
||||||
|
lam1 = 0.0;
|
||||||
|
beta = 0.0;
|
||||||
|
}
|
||||||
|
else if(Dist(p.StartPI(), s.EndPI())<EPSILON)
|
||||||
|
{
|
||||||
|
lam1 = 0.0;
|
||||||
|
beta = 1.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
IntersectSplineSegment1( s, p.StartPI(), s_mid, lam1, beta, true );
|
||||||
|
|
||||||
// Also check if midpoints lie on other spline
|
// Also check if midpoints lie on other spline
|
||||||
IntersectSplineSegment1( p, s.GetPoint(0.5), p_mid, lam2, alpha_mid, true );
|
IntersectSplineSegment1( p, s.GetPoint(0.4), p_mid, lam2, alpha_mid, true );
|
||||||
IntersectSplineSegment1( s, p.GetPoint(0.5), s_mid, lam3, beta_mid, true );
|
IntersectSplineSegment1( s, p.GetPoint(0.4), s_mid, lam3, beta_mid, true );
|
||||||
|
|
||||||
auto tang0 = s.GetTangent(0.);
|
auto tang0 = s.GetTangent(0.);
|
||||||
auto tang1 = p.GetTangent(alpha);
|
auto tang1 = p.GetTangent(alpha);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
from ngsolve import *
|
|
||||||
|
|
||||||
from random import random, seed
|
from random import random, seed
|
||||||
ngsglobals.msg_level = 0
|
from ngsolve import Draw, Mesh
|
||||||
|
|
||||||
import netgen
|
import netgen
|
||||||
from pyngcore import *
|
from pyngcore import *
|
||||||
@ -9,42 +7,31 @@ from netgen.geom2d import *
|
|||||||
|
|
||||||
seed(4)
|
seed(4)
|
||||||
|
|
||||||
def GenerateMesh():
|
g = CSG2d()
|
||||||
|
outer = Rectangle((0, 0), (1, 1), "outer","outer")
|
||||||
|
inner = Solid2d()
|
||||||
|
|
||||||
g = CSG2d()
|
for i in range(30):
|
||||||
g1 = CSG2d()
|
cx = random()
|
||||||
outer = Rectangle(0, 1, 0, 1,"outer","outer")
|
cy = random()
|
||||||
inner = Solid2d()
|
r = 0.03+0.05*random()
|
||||||
|
print("Add Circle", i, cx, cy, r, flush = True)
|
||||||
for i in range(30):
|
circle = Circle((cx, cy), r, "circle"+str(i), "circle"+str(i))
|
||||||
cx = random()
|
inner += circle
|
||||||
cy = random()
|
outer -= circle
|
||||||
r = 0.03+0.05*random()
|
|
||||||
print("Add Circle", i, cx, cy, r, flush = True)
|
|
||||||
circle = Circle(cx, cy, r, "circle"+str(i), "circle"+str(i))
|
|
||||||
g1.Add(circle)
|
|
||||||
inner += circle
|
|
||||||
outer -= circle
|
|
||||||
|
|
||||||
|
|
||||||
g.Add(inner)
|
g.Add(inner)
|
||||||
g.Add(outer)
|
g.Add(outer)
|
||||||
geo = g.GenerateSplineGeometry()
|
geo = g.GenerateSplineGeometry()
|
||||||
|
|
||||||
|
m = geo.GenerateMesh(maxh=0.1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ngsolve import Draw, Mesh
|
||||||
Draw(geo)
|
Draw(geo)
|
||||||
|
|
||||||
# draw this geometry for checking ff the final mesh/geometry is correct
|
|
||||||
# g1.Add(outer)
|
|
||||||
# geo1 = g1.GenerateSplineGeometry()
|
|
||||||
# Draw(geo1)
|
|
||||||
|
|
||||||
print('generate mesh')
|
|
||||||
m = geo.GenerateMesh(maxh=0.1)
|
|
||||||
mesh = Mesh(m)
|
mesh = Mesh(m)
|
||||||
mesh.Curve(3)
|
mesh.Curve(3)
|
||||||
Draw(mesh)
|
Draw(mesh)
|
||||||
|
except:
|
||||||
return mesh
|
pass
|
||||||
|
|
||||||
from ngsolve import Draw
|
|
||||||
with PajeTrace():
|
|
||||||
mesh = GenerateMesh()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user