Skip to content

Support for constructive geometry #251

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

Open
jondea opened this issue Mar 16, 2022 · 6 comments
Open

Support for constructive geometry #251

jondea opened this issue Mar 16, 2022 · 6 comments
Labels

Comments

@jondea
Copy link

jondea commented Mar 16, 2022

As part of a FEM project I have implemented an Annulus<:Primitive type and several related functions. Does this count as a primitive, as in there isn't some clever way to make it from two balls? And if not, is this something that would be welcome for a PR?

@juliohm
Copy link
Member

juliohm commented Mar 16, 2022

Hi @jondea thank you for proposing the primitive. I think what we really need is an API for constructive geometry. There are some packages out there already like

implementing subtraction, intersection and union of primitives. Ideally, we will be able to introduce these same operations in Meshes.jl reusing our primitive types to avoid inefficiencies with type conversion, and to help new users who just want to load a single ecosystem to get things done quickly.

@jondea
Copy link
Author

jondea commented Mar 16, 2022

Hi @juliohm, thank you for the pointers! That approach is certainly more elegant. I've made a branch with the Annulus type so I don't lose it https://github.com/jondea/Meshes.jl/tree/add-annulus-primitive, and I hope to be able to come back to this when I have more time.

@juliohm juliohm changed the title New primitive suggestion: annulus Support for constructive geometry Mar 17, 2022
@bjarthur
Copy link

i see the "Intersection" part of the manual, but don't see a union method anywhere. does it exist?

i ask because i have a mesh with overlapping quadrangles. would like to simplify it. in the MWE below, there are two quadrangles, but there could be just one ngon. how do i make it so? have tried simplify and repair to no avail. in the more general case, i have an arbitrary number of quadrangles, some of which might overlap, and others not. thx!

julia> using Meshes, GLMakie

julia> points1 = [(0,0), (2,0), (0,2), (2,2), (1,1), (1,3), (3,1), (3,3)];

julia> quads1 = connect.([(1,2,4,3), (5,6,8,7)], Quadrangle);

julia> mesh1 = SimpleMesh(points1, quads1)
2 SimpleMesh
  8 vertices
  ├─ Point(x: 0.0 m, y: 0.0 m)
  ├─ Point(x: 2.0 m, y: 0.0 m)
  ├─ Point(x: 0.0 m, y: 2.0 m)
  ├─ Point(x: 2.0 m, y: 2.0 m)
  ├─ Point(x: 1.0 m, y: 1.0 m)
  ├─ Point(x: 1.0 m, y: 3.0 m)
  ├─ Point(x: 3.0 m, y: 1.0 m)
  └─ Point(x: 3.0 m, y: 3.0 m)
  2 elements
  ├─ Quadrangle(1, 2, 4, 3)
  └─ Quadrangle(5, 6, 8, 7)

julia> viz(mesh1, color=:blue)
Image

@juliohm
Copy link
Member

juliohm commented May 15, 2025 via email

@bjarthur
Copy link

bjarthur commented May 15, 2025

so the idea is that if i create a second geometry which bounds both those quadrangles above, then i can use it to clip them and in the process they will be merged into a single geometry?

just tried it and seemingly SutherlandHodgman can't input meshes:

julia> other = Meshes.Box((0,3), (3,3))
Box
├─ min: Point(x: 0.0 m, y: 3.0 m)
└─ max: Point(x: 3.0 m, y: 3.0 m)

julia> clip(mesh1, other, SutherlandHodgmanClipping())
ERROR: MethodError: no method matching clip(::SimpleMesh{…}, ::Meshes.Box{…}, ::SutherlandHodgmanClipping)
The function `clip` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  clip(::Polygon, ::Geometry, ::SutherlandHodgmanClipping)
   @ Meshes ~/.julia/packages/Meshes/7KLYh/src/clipping/sutherlandhodgman.jl:21
  clip(::Ring, ::Ring, ::SutherlandHodgmanClipping)
   @ Meshes ~/.julia/packages/Meshes/7KLYh/src/clipping/sutherlandhodgman.jl:27

@juliohm
Copy link
Member

juliohm commented May 16, 2025

Sorry, I was typing from my phone and wasn't clear enough in my previous comment. Some of these clipping algorithms allow the calculation of set operations, see https://dl.acm.org/doi/pdf/10.1145/274363.274364

In particular, we could finalize the PR #1125 and use the data structures therein to compute the union.

The short answer for your question is that we don't currently support it. It is in the plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants