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

Find intersection for parallel, flat Meshes #1098

Open
IsabellaPa opened this issue Apr 18, 2024 · 7 comments
Open

Find intersection for parallel, flat Meshes #1098

IsabellaPa opened this issue Apr 18, 2024 · 7 comments

Comments

@IsabellaPa
Copy link

Hello,

I'm trying to find the intersection of two flat Meshes that lie on top of each other.
I was trying to do this with boolean at first, but I found here that it doesn't work if all normals point in the same directions.
So I tried intersection = mesh1.clone().cut_with_mesh(mesh2), which kind of does work but the result is not smooth. :( (see pictures below)
I played around with triangulate() and subdivide() in the hope that more triangles would make the outcome smoother but actually it made it worse and I got a result with even more cracks.

Any ideas how to get a better result? I was thinking about maybe changing the normals very little so they are not perfectly straight anymore to retry the boolean approach, but I'm unsure to do this.

Segments
Cutted

The meshes to cut are green and blue. The white cut is the result.

I would appreciate any help! :)

@marcomusy
Copy link
Owner

hi ..so your meshes are almost overlapping?
You maybe can try by measuring the distainces of the 2 meshes and then cut with the computed scalar

https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_scalar
https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.distance_to

mesh1.distance_to(mesh2, signed=True)
mesh1.cut_with_scalar(0, "Distance")

also have you tried
https://vedo.embl.es/autodocs/content/vedo/vedo/mesh.html#Mesh.intersect_with

@IsabellaPa
Copy link
Author

Yes, I projected the meshes to the same plane. I have something like a tunnel that changes its shape and have to find the area that is common along the tunnel length. So in the example that I've sent the shapes are pretty similar as the distance in the tunnel was very small but the shape can vary much more.

The approach with distances leads to similar results as before.
image

While intersect_with returns a collection of lines.
image

I also tried to find the points that are included in all shapes that I compare, but in the end I don't know how I could reconnect the points to an area again.

@marcomusy
Copy link
Owner

Sorry from what you have sent it is not clear to me at all what the "tunnel" is or where it is in the image.
Also if you projected on the "same plane" it means the 2 objects are coplanar - and in fact you have got lots of intersections.. so there is no space inbetween?
What is the red sphere?

@IsabellaPa
Copy link
Author

IsabellaPa commented Apr 23, 2024

Ah sorry. I made a sketch to clarify my problem. I think I spent too much time with it already :)

image
(1)
So the blue thing is my tunnel (I simplified the shape). And the green circles are the shape of the tunnel at specific heights, aka I intersect the tunnel with planes that are parallel to the yellow plane and save the intersection polygon. These intersections led to the blue and green shape that I posted earlier.
(2)
Then I project all my intersections onto the yellow plane. I want to find the red area that is common for all intersection polygons (green circles).

This projection is what I sent earlier. I didn't include images with the tunnel. The tunnel is made out of a vedo mesh.
The sphere is a landmark that's not used in this case, I just didn't take it out of the visualization. :)

I hope that makes it clearer? If not please let me know!

@marcomusy
Copy link
Owner

Ok now it is more clear..
you may create a copy of the 3d circles and shift it forward (and/or backwards along the normal) and form a cylindrical Ribbon mesh. You use then this mesh to .cut_with_mesh() the other ones that would be created in the same way until you are only left with the intersection. You may need to use .slice() to create a filled circle to be cut.

@IsabellaPa
Copy link
Author

IsabellaPa commented Apr 24, 2024

I'm not 100% sure if I understand correctly what you want to do with the ribbon. As far as I interpreted it the Ribbon fills the space between two boundaries/circles.
This works find for me if the meshes are a tiny bit apart but when I put them into the same plane they start to do funny things
image
Here in pink the ribbon.
I get my ribbon by:

intersection_circle = tunnel_mesh.intersect_with_plane(origin=new_center, normal=normal).join(reset=True)
mslices = vedo.pointcloud.merge(intersection_circle).color(color[distance]) 
mslices_boundaries = mslices.boundaries()
(I'm doing this for multiple outlines)

ribbon_mesh = Ribbon(mslices_boundaries_0, mslices_boundaries_1, closed =True, mode = 1).color('pink')

Results for mode 0 and mode 1 are not the same but similar in the problem. Setting closed = False also didn't help.

Also, in my tunnel the walls can sometimes touch in the middle so I have two separate circles or more at the same intersection height.

I do appreciate your help a lot!

@marcomusy
Copy link
Owner

You can play around with a test case to find the strategy that best fits your problem, consider this as a starting point:

from vedo import *

ln = [[sin(x), cos(x), x / 2] for x in np.arange(6,9, 0.1)]
N = len(ln)
radii = [0.3*(cos(6.0*ir/N))**2+0.1 for ir in range(N)]
tube = Tube(ln, r=radii, res=48).triangulate()

n = (0.3,-1,0)
slices = []
for i in range(-3, 6):
    sli = tube.slice(origin=[0,i/10,0], normal=n)
    sli.c("b9").bc("k5").lighting("off").pickable(True)
    # sli = tube.intersect_with_plane(origin=[0,i/10,0], normal=n)
    sli.reorient(n, [0,0,1])
    slices.append(sli)

show([tube, slices], N=2, sharecam=0, axes=1)

Screenshot from 2024-04-24 15-31-21

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

No branches or pull requests

2 participants