# How to represent the lines that are formed by the intersection of two planes?

I am trying to set up Brillouin zone and representing the lines that are formed by the intersection of two planes is part of my step. I have tried the sample sections from the graphics guide book, but I got some wrong output. Here is the code that I copied from the guidebook:

(* to save memory *) \$HistoryLength = 0;


The function latticePointListSC generates all lattice points that we want to take into account. It returns all lattice points inside a sphere of radius d around the origin.

latticePointListSC[d_] :=
With[{n = Ceiling[d]},
Select[
DeleteCases[
Flatten[Table[{i, j, k}, {i, -n, n}, {j, -n, n}, {k, -n, n}], 2],
(* without origin *){0, 0, 0}],
#. # <= d^2&]]

maxDist = 4;Length[latticePoints = latticePointListSC[maxDist]]

Show[Graphics3D[Cuboid[# + 0.1 {1, 1, 1},# - 0.1 {1, 1, 1}]& /@ latticePoints],
Axes -> True];


Next, we construct the perpendicular planes in the middle of the lines origin–latticePoint. We denote a plane in the form Plane[onePointOfThePlane, listOfTwoOrthogonalDirections].

The function toPlane generates a plane (head Plane) of the bisector plane formed by the point latticePoint.

toPlane[p:latticePoint_] :=
Plane[latticePoint/2,
Which[(* lattice point is on a coordinate axis *)
p == 0 && p == 0, {{1, 0, 0}, {0, 1, 0}},
p == 0 && p == 0, {{1, 0, 0}, {0, 0, 1}},
p == 0 && p == 0, {{0, 1, 0}, {0, 0, 1}},
(* lattice point is on a coordinate plane *)
p != 0 && p != 0, {#, Cross[#, p]}&[{p, -p, 0}],
p != 0 && p != 0, {#, Cross[#, p]}&[{p, 0, -p}],
p != 0 && [P3] != 0, {#, Cross[#, p]}&[{0, p, -p}],
(* lattice point is in generic position *)
True, {#, Cross[#, p]}&[{p, -p, 0}]]]


We are now adding some planes that guarantee that polygons are divided along the symmetry planes. A “symmetry unit” (for brevity, just called unit in the following) is given by the following domain x>=0, y>= 0, z>= 0, z >= x, x >=y. This is 1/48 of the whole space. The list symmetrySlicingPlanes contains the planes that bound the unit.

symmetrySlicingPlanes =
Plane[{0, 0, 0}, #]& /@
{{{1, 0, 0}, {0, 1, 0}}, {{1, 0, 0}, {0, 0, 1}},{{0, 1, 0}, {0, 0, 1}},
{{0, 0, 1}, {-1, 1, 0}}, {{0, 0, 1}, {1, 1, 0}}, {{1, 0, 0}, {0, -1, 1}},
{{1, 0, 0}, {0, 1, 1}}, {{0, 1, 0}, {-1, 0, 1}},{{0, 1, 0}, {1, 0, 1}}};


Here are the symmetrySlicingPlanes. The red, slightly sticking out polygons mark one symmetry unit. We will in the following concentrate on this unit and only later in the visualization part generate all other 47 units by reflection and rotation.

With[{ε = 0.05},
Show[
Graphics3D[{
(* make polygons *)
Polygon[{# - #[2, 1] - #[2, 2],
# + #[2, 1] - #[2, 2],
# + #[2, 1] + #[2, 2],
# - #[2, 1] + #[2, 2]}]& /@ symmetrySlicingPlanes,
{SurfaceColor[Hue],
(* lift a bit up *)
Map[# + {ε, ε, 2ε}&,
(* boundary of the unit cone *)
{Polygon[{{0, 0, 0}, {0, 0, 1}, {1, 0, 1}}],
Polygon[{{0, 0, 0}, {0, 0, 1}, {1, 1, 1}}],
Polygon[{{0, 0, 0}, {1, 0, 1}, {1, 1, 1}}]},
{-2}]}}],
Boxed->False]]

planes =
Join[toPlane /@ latticePoints, symmetrySlicingPlanes];
Take[planes, 4]


Next, we construct representations of the lines that are formed by the intersection of two planes. The presentation of the lines will be in the form Line[onePointOfTheLine, lineDirection]. We use here a two-argument version of Line, in distinction to the built-in Line, which takes one argument. The function lineOnPlane[plane1, plane2] calculates the intersection line which is located on plane1 , induced by its intersection with the plane plane2 .

(* three equations cannot be solved for four variables *)
Off[Solve::"svars"];
lineOnPlane[Plane[p_, {dir1_, dir2_}], Plane[q_, {d1_, d2_}]] :=
Module[{eqs, sol, line, var, aux, P1, P2},
If[
(* are the planes parallel? *)
Length[DeleteCases[RowReduce[{dir1, dir2, d1, d2}], {0, 0, 0}, {1}]] == 2,
{},
(* calculate direction of the intersecting line *)
eqs = Thread[p + s dir1 + t dir2 == q + u d1 + v d2];
sol = Solve[eqs, {s, t, u, v}];
aux = p + s dir1 + t dir2 /. sol[];
(* two points on the line *)
{P1, P2} = {aux /. {u -> 0, v -> 0}, aux /. {u -> 1, v -> 1}};Line[P1, P2 - P1]]]

lineOnPlane[planes[], planes[]]


I should have gotten

Line[{-2, 1, -1}, {0, -20, 10}]


but i got

Line[{-2, s, -(1/2) - s/2}, {0, 0, 0}]


The lines after this all got messed up beacuse of the wrong out Could anyone please help? Is there a better way I could do compute the lines that are formed by the intersection of two planes?

• This question looks very similar to the one you last posted (and that went through a lot of edits, last one by @OleksandrR.)? It seems wasteful to have people put effort into edits of multiple, nearly identical questions. – Yves Klett Jun 18 '14 at 5:38

From a first look, late at night.

In the third panel of code, aren't all of the terms really parts of a list p, and should therefore be written as p[], p[], etc., rather than p, p, etc. The paired single square brackets would surround the argument(s) of a function, e.g. Sin[x] or Sqrt[x]; paired double square brackets designate an element of a list. There is also a typo: what appears as [p3] is almost certainly intended to be p[].

In the fifth panel of code, below the comment (*make polygons*), shouldn't all of the terms be double square brackets , such as #[], #[], etc. rather than #, #? When mapping the Polygon onto symmetrySlicingPlanes you are extracting parts from each of the elements of the symmetrySlicingPlanes list, not making function evaluations with paired single square brackets.

Once I changed a lot of [ ] cases to [[ ]] cases and corrected a typo, I got the following for the Graphics3D. Is this what you expect? [I got the same final result as you got for lineOnPlane[planes[], planes[]], but I think printing some intermediate results leading up to that answer, such as

eqs = {-2==-(3/2)-u-6 v, s==-(1/2)+3 u-2 v, t==-1+10 v}

sol = {{t->-(1/2)-s/2, u->1/5+(3 s)/10, v->1/20-s/20}}

aux = {-2,s,-(1/2)-s/2}

Line[{-2, s, -(1/2) - s/2}, {0, 0, 0}]

should provide clues as to what is wrong and how this needs to be fixed. Too late at night now.

P.S. The printing did supply some clues, and I think the code below now gives the answer you desire, but you really need to check this yourself. I'm not familiar enough with this particular type of calculation.

latticePointListSC[d_] :=

With[{n = Ceiling[d]},

Select[

DeleteCases[

Flatten[

Table[{i, j, k}, {i, -n, n}, {j, -n, n}, {k, -n, n}],

2],

(*without origin*){0, 0, 0}],

#.# <= d^2 &]]

maxDist = 4;

Length[latticePoints = latticePointListSC[maxDist]]

(* 256 *)

g3d1 = Show[

Graphics3D[

Cuboid[# + 0.1 {1, 1, 1}, # - 0.1 {1, 1, 1}] & /@ latticePoints

],

Axes -> True];

Raster[Image[g3d1, ImageSize -> 4*72]]  (*No way to include this graphic in answer.*)

(*Notice the many double square brackets that are in this toPlane function now*)

(*when compared with the original.*)

toPlane[p : latticePoint_] := Plane[latticePoint/2,

Which[

(*lattice point is on a coordinate axis*)

p[] == 0 && p[] == 0,

{{1, 0, 0}, {0, 1, 0}},

p[] == 0 && p[] == 0,

{{1, 0, 0}, {0, 0, 1}},

p[] == 0 && p[] == 0,

{{0, 1, 0}, {0, 0, 1}},

(*lattice point is on a coordinate plane*)

(*WATCH OUT--IN THE NEXT THREE CONDITIONALS*)

(*I ADDED A THIRD && CONDITION THAT WAS NOT IN THE ORIGINAL*)

(*I COULD BE WRONG--I"M NO EXPERT ON THIS*)

p[] != 0 && p[] != 0 && p[] == 0,

{#, Cross[#, p]} &[{p[], -p[], 0}],

p[] != 0 && p[] != 0 && p[] == 0,

{#, Cross[#, p]} &[{p[], 0, -p[]}],

p[] != 0 && p[] != 0 && p[] == 0,

{#, Cross[#, p]} &[{0, p[], -p[]}],

(*lattice point is in generic position*)

True,

{#, Cross[#, p]} &[{p[], -p[], 0}]
]]

symmetrySlicingPlanes =

Plane[{0, 0, 0}, #] & /@

{

{{1, 0, 0}, {0, 1, 0}}, {{1, 0, 0}, {0, 0, 1}}, {{0, 1, 0}, {0, 0,1}},

{{0, 0, 1}, {-1, 1, 0}}, {{0, 0, 1}, {1, 1, 0}}, {{1, 0, 0}, {0, -1, 1}},

{{1, 0, 0}, {0, 1, 1}}, {{0, 1, 0}, {-1, 0, 1}}, {{0, 1, 0}, {1, 0, 1}}

};

g3d2 = With[{\[CurlyEpsilon] = 0.05},

Show[

Graphics3D[

{(*make polygons*)

Polygon[{#[] - #[[2, 1]] - #[[2, 2]], #[] + #[[2, 1]] - #[[ 2, 2]],

#[] + #[[2, 1]] + #[[2, 2]], #[] - #[[2, 1]] + #[[2, 2]]}]

& /@ symmetrySlicingPlanes,

{

SurfaceColor[Hue],(*lift a bit up*)

Map[# + {\[CurlyEpsilon], \[CurlyEpsilon],

2 \[CurlyEpsilon]} &,

(*boundary of the unit cone*)

{Polygon[{{0, 0, 0}, {0, 0, 1}, {1, 0, 1}}],

Polygon[{{0, 0, 0}, {0, 0, 1}, {1, 1, 1}}],

Polygon[{{0, 0, 0}, {1, 0, 1}, {1, 1, 1}}]}, {-2}]

}

}

],

Boxed -> False]

]

Raster[Image[g3d2, ImageSize -> 4*72]]

planes = Join[toPlane /@ latticePoints, symmetrySlicingPlanes];

Take[planes, 4];

Off[Solve::"svars"];

lineOnPlane[Plane[p_, {dir1_, dir2_}], Plane[q_, {d1_, d2_}]] :=

Module[

{eqs, sol, line, var, aux, P1, P2},

If[

(*are the planes parallel?*)

Length[

DeleteCases[RowReduce[{dir1, dir2, d1, d2}], {0, 0, 0}, {1}]

] == 2,

{},

(*calculate direction of the intersecting line*)

eqs = Thread[p + s dir1 + t dir2 == q + u d1 + v d2];

Print["eqs = ", eqs];

(*BIG CHANGE IN SOLVE ON NEXT LINE!*)
(*Now solving for {s,t,u}, NOT {s, t, u, v}, as in original*)

sol = Solve[eqs, {s, t, u}];

Print["sol = ", sol];

aux = ((p + s dir1 + t dir2) /. sol[]);

Print["aux = ", aux];

(*two points on the line*)

{P1, P2} = {aux /. {u -> 0, v -> 0}, aux /. {u -> 1, v -> 1}};

Line[P1, P2 - P1]

]

]

lineOnPlane[planes[], planes[]]

(* Prints:  eqs = {-2==-(3/2)-u-6 v, s==-(1/2)+3 u-2 v, t==-1+10 v} *)

(* Prints:  sol = {{s->1-20 v, t->-1+10 v, u->1/2 (1-12 v)}} *)

(* Prints:  aux = {-2,1-20 v,-1+10 v} *)

(* Line[{-2, 1, -1}, {0, -20, 10}] *)


I cannot promise that these changes are correct--you must check them. You should remove the three Print[] functions; I used them for the diagnostic work I was doing, but they are not necessary.

New errors have probably been introduced in the course of all of the copy and paste work necessary to move my Mathematica notebook code to this answer window. This is not an efficient way to answer a question with so much intricate code. Would have been better to e-mail you my .nb, but I think this site is not intended for exchanging .nb files.

I hope this helps you somewhat though.

• Thank you for pointing out the typo, it's just that copying onto this website accidentally dropped the bracket. Could you elaborate on how to fix it? Sorry i am a beginner... – Jenny Jun 18 '14 at 16:16
• By the way the figure looked right. – Jenny Jun 18 '14 at 16:18
• Did the code above work for you? – user15996 Jun 20 '14 at 2:02
• ,oh my god, you are awesome! The code worked! I really appreciate your help! Thank you so much!!! – Jenny Jun 20 '14 at 13:26

This problem is now easier to resolve in the current version. I will also take the opportunity to simplify some of the code used above.

Thus:

latticePointListSC[d_] := With[{n = Ceiling[d]},
Select[DeleteCases[Flatten[CoordinateBoundsArray[ConstantArray[{-n, n}, 3]],
2], {0, 0, 0}], #.# <= d^2 &]]

With[{maxDist = 4},
Graphics3D[Cuboid[# + {1, 1, 1}/10, # - {1, 1, 1}/10] & /@
(latticePoints = latticePointListSC[maxDist]), Axes -> True]] toPlane[p_?VectorQ] := Module[{c, dir, pos, x, y, z},
{x, y, z} = p;
If[FreeQ[p, 0], (* normal case *)
dir = {#, Cross[#, p]} &[{y, -x, 0}],
c = Count[p, 0];
If[c == 2 (* on an axis *),
dir = Pick[IdentityMatrix, p, 0],
(* on a coordinate plane *)
pos = Position[p, 0];
dir = {#, Cross[#, p]} &[Insert[Cross[Delete[p, pos]], 0, pos]]]];
InfinitePlane[p/2, dir]]

symmetrySlicingPlanes = InfinitePlane[{0, 0, 0}, #] & /@
{{{1, 0, 0}, {0, 1, 0}}, {{1, 0, 0}, {0, 0, 1}}, {{0, 1, 0}, {0, 0, 1}},
{{0, 0, 1}, {-1, 1, 0}}, {{0, 0, 1}, {1, 1, 0}}, {{1, 0, 0}, {0, -1, 1}},
{{1, 0, 0}, {0, 1, 1}}, {{0, 1, 0}, {-1, 0, 1}}, {{0, 1, 0}, {1, 0, 1}}};

With[{ε = 0.05},
Graphics3D[{symmetrySlicingPlanes, {Red,
Map[# + {ε, ε, 2 ε} &,
{Polygon[{{0, 0, 0}, {0, 0, 1}, {1, 0, 1}}],
Polygon[{{0, 0, 0}, {0, 0, 1}, {1, 1, 1}}],
Polygon[{{0, 0, 0}, {1, 0, 1}, {1, 1, 1}}]}, {-2}]}},
Boxed -> False, Method -> {"RelieveDPZFighting" -> True},
PlotRange -> 1]] planes = Join[toPlane /@ latticePoints, symmetrySlicingPlanes];

RegionIntersection[planes[], planes[]]
InfiniteLine[{-2, 1, -1}, {0, -20, 10}]