# How to define two polyhedron intersect or not?

Recently I have used Mathematica to simulate the concrete structure. The most important point is generate random concrete aggregate. As you know, concrete aggregate can be looked as a polyhedron.

We can use ConvexHull to generate polyhedron.

Needs["TetGenLink"];

data3D = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
Graphics3D[Point[data3D]];

{pts, surface} = TetGenConvexHull[data3D];
Graphics3D[GraphicsComplex[pts, Polygon[surface]]];


Question 1: How to define two polyhedron intersect or not?

I have written a Module, But its speed is very slow.

Question 2: When the concrete aggregate become more and more in a cubic region, it is very difficult to add new aggregate in the region, How can deal with this problem ?

The key is define the space relationship between line(segment) and plane(triangle):

HelenFormulaofTriangle[triangle_] := Module[
{a, b, c, p},

a = Norm[(triangle[[1]] - triangle[[2]])];
b = Norm[(triangle[[1]] - triangle[[3]])];
c = Norm[(triangle[[2]] - triangle[[3]])];

p = 0.5*(a + b + c);

Sqrt[p*(p - a)*(p - b)*(p - c)]

(*
triangle={{0,0,0},{1,0,0},{0,1,0}};
HelenFormulaofTriangle[triangle];
*)

];

PointInandOnorOut3DTriangle[point_, triangle_] := Module[
{},

If[
HelenFormulaofTriangle[{point, triangle[[1]], triangle[[2]]}] +
HelenFormulaofTriangle[{point, triangle[[1]], triangle[[3]]}] +
HelenFormulaofTriangle[{point, triangle[[2]], triangle[[3]]}] >
HelenFormulaofTriangle[triangle],
0,
1]

];

triangle={{0,0,0},{1,0,0},{0,1,0}};
HelenFormulaofTriangle[triangle];
point={0,0,1};
PointInandOnorOut3DTriangle[point,triangle];


-
For the first question, do you mean "how to decide if 2 polyhedrons are intersecting"? Then, I can't understand your second question very well. – xzczd Jul 19 '14 at 3:31
Could you show the code you have so far? – user21 Jul 19 '14 at 6:35
Yes,I mean how to decide if 2 polyhedrons are intersecting – YuYong Jul 19 '14 at 6:39
Please have a look at this and format your code just as @jtbandes did for you. – xzczd Jul 19 '14 at 6:55
Well, if you want to call someone who isn't the original poster that appearing in the comment, you need to add @someone in your comment, or others won't see the reminder. RegionIntersection can be used for 3D object, for example d1 = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; d2={{0,0,0},{1/2,1/2,1/2},{1,0,0},{1,1,0}};r=RegionIntersection@@(Tetrahedron/@{‌​d1,d2});RegionMember[r,{x,y,z}]//Reduce` – xzczd Jul 21 '14 at 3:10
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}