1
$\begingroup$

I am trying to use CSPlotter, which is a way of visualizing the contact structure of $\mathbb{R}^3$ by plotting several sections of planes. It is written for an old version of Mathematica. I included the package code at the end. I tried to run

<<CSPlotter.m
xmin = -3.5; xmax = 3.5; dx = (xmax - xmin)/14;
ymin = -3.5; ymax = 3.5; dy = (ymax - ymin)/16;
size = dy;

normal[x_, y_, z_] = {-2y, 2x, 1};

Table[contactelement[{x, y, 0}, normal[x, y, 0], size], {x, xmin, 
   xmax, dx}, {y, ymin, ymax, dy}];
out = Show[%, coords[xmax + 1, ymax + 1, 3.4], Boxed -> False]

I get the error

Show: Could not combine the objects in 

and it shows the separate planes that are created. It should produce a plot like this

The CSPlotter code is here

Rotvect[v_] :=
  Module[
    {ex, ey, ez},
    If[v[[1]] == 0 && v[[2]] == 0,
     Return[{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}];
      ]; 
    ez = v/Sqrt[v.v];
    ey = 1/Sqrt[v[[1]]^2 + v[[2]]^2] {-v[[2]], v[[1]], 0};
    ex = Cross[ey, ez];
    Transpose[{ex, ey, ez}]  
]

(*
 *  contactelement[disp, covect, scale]
 *   
 *  Returns a rectange centered at 'disp', normal to 'covect' 
 *  and of size 'scale' as a Mathematica Graphics3D object.
 *
 *)
contactelement[disp_, covect_, scale_] :=
  Module[
    {P, b1, b2, b3, b4},
    b1 = {-1/2, -1/2, 0}; b2 = {-1/2, 1/2, 0}; b3 = {1/2, 1/2, 0}; 
    b4 = {1/2, -1/2, 0};
    P = Rotvect[covect];
    gs = Graphics3D[Polygon[scale{ P.b1, P.b2, P.b3, P.b4}], Boxed -> False, 
        PlotRange -> All];
    gs = TranslateShape[gs, disp]
    ]


(*
 *  coords[xmax, ymax, zmax]
 *   
 *  returns (as a Mathematica Graphics3D object) coordinate
 *  axes of lengths 'xmax', 'ymax', and 'zmax', respectively. 
 *)

coords[xmax_, ymax_, zmax_] :=
  Graphics3D[
    {
      Line[{{0, 0, 0}, {0, 0, zmax}}],
      Line[{{0, 0, 0}, {0, ymax, 0}}],
      Line[{{0, 0, 0}, {xmax, 0, 0}}],
      Text["x", {xmax + 0.25, 0, 0}],
      Text["y", {0, ymax + 0.25, 0}],
      Text["z", {0, 0, zmax + 0.25}]
    },
    PlotRange -> All]

I removed the lines that include 'Shapes.m' and 'VectorAnalysis.m' since Mathematica said it is built in to the current version. Is there a simple error I made in trying to use the package or can I modify the package so that it works in the newer version?

$\endgroup$

1 Answer 1

1
$\begingroup$

When I remove the TranslateShape and simply translate the coordinates by using

contactelement[disp_, covect_, scale_] := 
 Module[{P, b1, b2, b3, b4, gs}, b1 = {-1/2, -1/2, 0}; 
  b2 = {-1/2, 1/2, 0}; b3 = {1/2, 1/2, 0};
  b4 = {1/2, -1/2, 0};
  P = Rotvect[covect];
  Graphics3D[
   Polygon[scale (Plus[disp, #] & /@ {P.b1, P.b2, P.b3, P.b4})], 
   Boxed -> False, PlotRange -> All]
 ]

I get

Show[Table[
  contactelement[
    {x, y, 0}, normal[x, y, 0], size], 
  {x, xmin, xmax, dx}, {y, ymin, ymax, dy}]]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.