Code Monkey home page Code Monkey logo

Comments (8)

juliohm avatar juliohm commented on August 22, 2024 1

@CNOT can you please open a separate issue with this MWE? It doesn't seem related.

from meshes.jl.

juliohm avatar juliohm commented on August 22, 2024 1

This bug is now fixed. The original article contains the following theorem:

image

There is an additional condition on the first vertex Q1 of the segment: it must not be coplanar with the triangle. In this case, we need to swap the vertices Q1 and Q2 before running the algorithm.

A patch release in on its way.

from meshes.jl.

juliohm avatar juliohm commented on August 22, 2024

Thank you @jtveiten for reporting the issue. I can reproduce it.

It is a corner point intersection:

viz([s1, t1], color = ["red", "teal"])

image

The bug is in the intersection result. We will investigate when we find some time. Feel free to submit a PR in the meantime.

from meshes.jl.

juliohm avatar juliohm commented on August 22, 2024

@dorn-gerhard did you write our intersection(::Segment, ::Triangle) method? The fix may consist of a simple change from < to <= somewhere in the function body.

from meshes.jl.

dorn-gerhard avatar dorn-gerhard commented on August 22, 2024

Hi,
I cannot find an implementation for intersects(::Segment, ::Triangle) in src/predicates/intersects.jl
Not sure why it returns true.

No, I haven't implemented Triangle - Segment.
I was thinking about it but a while ago using a generalization of intersectparameters to more dimensions, then we got stuck in that discussion of #325 where I wanted to fix names for intersection Types. Then they got refactored which simplified a lot.

I think another refactoring might be necessary to consider intersection of objects of different dimensionality.
e.g. each object has an inner part, e.g. interval 0 < x < 1 and an outer part = boundary (segment end points, ray origin, edges of triangle, surface of 3d sphere).

  • if a subset of the outer part with no inner points equals the intersection set it should be called Touching,
  • if a subset of inner parts with a dimensionality less the original geometry is in the intersection set, I would call it Crossing
  • if a subset of inner parts with the same dimensionality as the original geometry is in the intersection set, I would call it Overlapping (I would dismiss Pos and NegOverlapping as the result is clear from the intersection object (Segment vs. Ray)

Since we have two Geometries A and B in an intersection we could have combinations of these three cases above.
e.g.

  • OverlappingTouching: A Segment that touches the edge of a Triangle
  • OverlappingCrossing: A Segment that crosses a Triangle in plane yielding a segment
  • TouchingCrossing: A Segment that crosses the origin of Ray (not parallel)

A Ray touching a corner of a Triangle (could be both also in the same plane) would be TouchingCrossing instead of CornerTouching
A Ray touching the edge of a Triangle (both not in the same plane) would also be called TouchingCrossing instead of EdgeTouching
A Ray overlapping with the edge of a Triangle (in the same plane) would be called OverlappingTouching
Not sure if CornerTouching and EdgeTouching is relevant for an algorithm.

Btw: segments, lines or rays that lie in the same plane as the triangle might not yield results:

t1 = Triangle((1.0,0.,0.),(0.,1.,0.),(0.,0.,1.))
s1 = Segment((1.0,0.,0.),(0.,1.,0.))
intersection(t1,s1)

from meshes.jl.

juliohm avatar juliohm commented on August 22, 2024

I cannot find an implementation for intersects(::Segment, ::Triangle) in src/predicates/intersects.jl
Not sure why it returns true.

You can use the @which macro to find the method that gets called:

julia> @which intersects(s1, t1)
intersects(c::Chain, g::Geometry)
     @ Meshes ~/.julia/dev/Meshes/src/predicates/intersects.jl:64

In this case we have a general method for Chain and Geometry. You can also discover this using the VSCode debugger by typing @enter intersects(s1, t1) and then following the steps.

I think another refactoring might be necessary.

These are very welcome. We are always doing that to improve the code organization.

Btw: segments, lines or rays that lie in the same plane as the triangle might not yield results

The intersection is the one with the bug in this issue. You can find the method here:

function intersection(f, seg::Segment{3,T}, tri::Triangle{3,T}) where {T}

from meshes.jl.

dorn-gerhard avatar dorn-gerhard commented on August 22, 2024

I added an issue / suggestion: #734 with a better description for refactoring intersection types using inner and outer points and their dimensionality to define Overlapping, Crossing and Touching for general geometries

from meshes.jl.

CNOT avatar CNOT commented on August 22, 2024

I'm not sure this is the same bug, but even in the 2D case intersection/clipping return incorrect values. Here's a MWE that I hope could be helpful for rooting out the issue:

using Meshes
using CairoMakie
cg = Meshes.CartesianGrid((0.0, 0.0), (2.0, 1.0), (0.1, 0.1))
ps = Meshes.Point2[(0.0, 0.0), (1.0, 0.5), (1.0, 1.0), (2.0, 0.0)]
pol = Meshes.PolyArea(ps)
viz(pol,showfacets = true)
for i in faces(cg, 2)
    cl = i  pol # Same thing happens with clip(i,pol, SutherlandHodgman())
    if cl != nothing
        viz!(i,showfacets = true, alpha = 0.5, facetcolor = :red)
    end
end
Makie.current_figure()

mwe

from meshes.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.