MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Transformation of 3D Objects to 2D Parallel-projection

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108723] Re: Transformation of 3D Objects to 2D Parallel-projection
  • From: Mark McClure <mcmcclur at unca.edu>
  • Date: Mon, 29 Mar 2010 05:22:21 -0500 (EST)

On Sun, Mar 28, 2010 at 7:55 AM, Peter Breitfeld <phbrf at t-online.de> wrote:
> I wrote some routines to map 3D-coordinates to 2D using the
> transformation
> proj[{x_,y_,z_}]:={y-x/2,z-x/2}
>
> But this doesn't work for all kind of 3D-objects.
> ...
> So my question: Is it possible to have routines, which will work on any
> kind of 3D-primitives including Cuboid[], Cylinder[] etc, which will
> preserve Thickness, Color etc

I'd suggest that you use patterns to write a different version of proj
for each primitive that you want to work with.  Thus, you might have
some lines like the following.

proj[{x_?NumericQ, y_?NumericQ, z_?NumericQ}] := {y - x/2, z - x/2};
proj[list_List] := proj /@ list;
proj[Point[pts_]] := Point[proj[pts]];
proj[Line[x_]] := Line[proj[x]];
proj[Arrow[x_]] := Arrow[proj[x]];
proj[Polygon[x_, pOpts___]] := Polygon[proj[x], pOpts];

To deal with something like Cylinder or Cuboid, you'll need to
translate it two an appropriate 2D primitive to represent the
projection.  You might deal with a Cuboid like so

Needs["ComputationalGeometry`"];
proj[Cuboid[{xmin_, ymin_, zmin_}, {xmax_, ymax_, zmax_}]] :=
  Module[{},
   vv = Tuples[{{xmin, xmax}, {ymin, ymax}, {zmin, zmax}}];
   projected = proj[vv];
   Polygon[projected[[ConvexHull[projected]]]]];
proj[Cuboid[{xmin_, ymin_, zmin_}]] := proj[Cuboid[{xmin, ymin, zmin},
    {xmin + 1, ymin + 1, zmin + 1}]];

At the end of it all, include

proj[x_] := x;

to ignore everything else, such as Graphics directives.  Here's an
example that might or might not illustrate the idea.

pic3D = Graphics3D[primitives = {
     {Thick, Line[{{{0, 0, 0}, {1, 1, 1}}, {{1, 0, 0}, {0, 1, 1}},
        {{0, 1, 0}, {1, 0, 1}}, {{0, 0, 1}, {1, 1, 0}}}]},
     {Opacity[0.5], Cuboid[{1/4, 1/4, 1/4}, {3/4, 3/4, 3/4}]}}];
pic2D = Graphics[proj[primitives]];
GraphicsRow[{pic3D, pic2D}]

Dealing with GraphicsComplex is easier in some ways.  Since it has the form

GraphicsComplex[points, primitives]

you simply map proj onto the points.  But you'll need to extract
Cuboids, Cylinders, Spheres and such (perhaps using Cases) to deal
with them separately.

Hope that helps,
Mark McClure


  • Prev by Date: Re: Mathematica starts badly 1 time over 5 in OSX
  • Next by Date: Re: Combinations Dispositions Permutations TREE
  • Previous by thread: Re: Transformation of 3D Objects to 2D Parallel-projection
  • Next by thread: Re: Transformation of 3D Objects to 2D Parallel-projection