Skip to content
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

Box - Ball intersection in 2D #1165

Open
aj-fleming opened this issue Jan 22, 2025 · 3 comments
Open

Box - Ball intersection in 2D #1165

aj-fleming opened this issue Jan 22, 2025 · 3 comments
Labels
feature help wanted Extra attention is needed

Comments

@aj-fleming
Copy link

The documentation for intersection reads

Compute the intersection of two geometries or domains g₁ and g₂ and apply function f to it. Default function is identity.

One might then expect to be able to run

orb = Meshes.Ball((0., 0.), 1.0)
square = Meshes.box((0.0, 0.0), (1.0, 1.0))
intersection(measure, orb, square)

which results in a StackOverflowError.

Perhaps "intersection" is not intended for this purpose?

@juliohm
Copy link
Member

juliohm commented Jan 22, 2025

We really need a FAQ for this. There are multiple issues closed about the same stack overflow.

The pair Ball + Box is not implemented currently. What are you trying to achieve?

@juliohm juliohm changed the title StackOverflow in intersection(::Box, ::Ball) Box - Ball intersection in 2D Jan 22, 2025
@juliohm juliohm added help wanted Extra attention is needed feature labels Jan 22, 2025
@aj-fleming
Copy link
Author

If it's a known issue, would it be appropriate to add a warning in the documentation?

I would like to generate a Cartesian grid of data points, and clip it using a ball. Ideally, the segments would be cut by the ball and turn the cartesian mesh into a "mostly cartesian" mesh, with some Quadrangles converted into other NGons by the intersection with the ball.

Perhaps I'm approaching the problem completely wrong, I've only spent an afternoon with the package.

@juliohm
Copy link
Member

juliohm commented Jan 23, 2025

If it's a known issue, would it be appropriate to add a warning in the documentation?

That would be great, though I feel that people will continue opening issues on GitHub. The problem lies in the fact that we exploit the symmetry of the intersection and write a fallback intersection(f, a, b) = intersection(f, b, a). When the fallback doesn't exist, Julia goes in an infinity loop flipping the arguments.

We tried to address this issue in the past, but the design became much more convoluted. We aborted the attempt. If you have a better suggestion that avoid code repetition, please feel free to submit a PR.

I would like to generate a Cartesian grid of data points, and clip it using a ball. Ideally, the segments would be cut by the ball and turn the cartesian mesh into a "mostly cartesian" mesh

I think you can already achieve this if you convert the Ball into a polygon:

using Meshes

b = Ball((0, 0), 1)

# sample points on boundary
s = sample(boundary(b), HomogeneousSampling(10))

# approximate ball with polygon
p = PolyArea(collect(s))

The intersection between the Quadrangles of the CartesianGrid and the PolyArea above is available.

Related discussion: #402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants