From: Dingzhou Cao on
Hi

Anyone know how to check 2 3D objects intersect with each other?
For example, how to check to whether 2 cylinders join with each other?
In 2D, function inpolygon can be used to check whether a point is inside a polygon or not, is there any similar function can be used in 3D case?

Thanks!

DZ
From: John D'Errico on
"Dingzhou Cao" <dingzhoucao(a)yahoo.com> wrote in message <hoh9ck$clg$1(a)fred.mathworks.com>...
> Hi
>
> Anyone know how to check 2 3D objects intersect with each other?
> For example, how to check to whether 2 cylinders join with each other?
> In 2D, function inpolygon can be used to check whether a point is inside a polygon or not, is there any similar function can be used in 3D case?
>

Even in 2-d, inpolygon does NOT check that two polygons
intersect. It is trivial to create a pair of triangles that do
indeed intersect, yet no vertex of a triangle is inside the
other.

John
From: Dingzhou Cao on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hohjmm$e69$1(a)fred.mathworks.com>...
> "Dingzhou Cao" <dingzhoucao(a)yahoo.com> wrote in message <hoh9ck$clg$1(a)fred.mathworks.com>...
> > Hi
> >
> > Anyone know how to check 2 3D objects intersect with each other?
> > For example, how to check to whether 2 cylinders join with each other?
> > In 2D, function inpolygon can be used to check whether a point is inside a polygon or not, is there any similar function can be used in 3D case?
> >
>
> Even in 2-d, inpolygon does NOT check that two polygons
> intersect. It is trivial to create a pair of triangles that do
> indeed intersect, yet no vertex of a triangle is inside the
> other.
>
> John

Hi John,

Thanks so much for your reply! You are right, inpolygon can not check that two polygons intersect, but we can check the vertex of one is inside the other or not.
In 3-D, I have not clue to do so. By the way, the surface of my 3-D object is approximated by triangles, which means I have the points coordinates of surface.

DZ
From: Alan Weiss on
Dingzhou Cao wrote:
> "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message
> <hohjmm$e69$1(a)fred.mathworks.com>...
>> "Dingzhou Cao" <dingzhoucao(a)yahoo.com> wrote in message
>> <hoh9ck$clg$1(a)fred.mathworks.com>...
>> > Hi
>> > > Anyone know how to check 2 3D objects intersect with each other?
>> > For example, how to check to whether 2 cylinders join with each other?
>> > In 2D, function inpolygon can be used to check whether a point is
>> inside a polygon or not, is there any similar function can be used in
>> 3D case?
>> >
>> Even in 2-d, inpolygon does NOT check that two polygons
>> intersect. It is trivial to create a pair of triangles that do
>> indeed intersect, yet no vertex of a triangle is inside the
>> other.
>>
>> John
>
> Hi John,
>
> Thanks so much for your reply! You are right, inpolygon can not check
> that two polygons intersect, but we can check the vertex of one is
> inside the other or not.
> In 3-D, I have not clue to do so. By the way, the surface of my 3-D
> object is approximated by triangles, which means I have the points
> coordinates of surface.
>
> DZ

If you have Optimization Toolbox(TM), you can specify your objects as
linear or nonlinear inequality constraints. For example, an ellipsoid
x^2/a^2 + y^2/b^2 + z^2/c^2 <= d
can be expressed as
cineq(x) = x(1)^2/a^2 + x(2)^2/b^2 + x(3)^2/c^2 - d

Use fmincon to minimize the function 1 subject to all your constraints.
fmincon will attempt to find a point that satisfies all your
constraints. If it succeeds, you obtain a point in the intersection, and
a positive exit flag.

Alan Weiss
MATLAB mathematical toolbox documentation
From: Bruno Luong on

>
> Thanks so much for your reply! You are right, inpolygon can not check that two polygons intersect, but we can check the vertex of one is inside the other or not.
> In 3-D, I have not clue to do so. By the way, the surface of my 3-D object is approximated by triangles, which means I have the points coordinates of surface.
>


For 3D you can check if the origin P (0 here) is located inside a volume V delimited by surface S by computing

I := integrate_S (<P . n> /|P|^3 ) dS = k*4*pi

where n, is the unit exterior normal to V.

If k = 1, P is inside
If k = 0, P is outside

This comes from Gauss's law.

The total integration is carried out by summing the integrals on individual triangles forming the mesh of S.

If P is not origin, shift the coordinates appropriately before checking as indicated.

Bruno