Message Boards Message Boards

0
|
5316 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Problems with Translation

Posted 9 years ago

For a class project, I am trying to make a 3D object which includes a fleet of ships heading toward an island. I was planning to make one ship and translate it to many locations. However I've run into a dilemma. The method I am using to show the translation of the copied ship object has run into a snag and I'm wondering what I'm doing wrong. This is what I used without including the translation:

    K1 = ParametricPlot3D[{(1 - 2 b) (7 + Cos[b]) Cos[
          8 Pi*a], (1 - a) (3 + Cos[4 b]) Sin[8*Pi*a], 
        4 a + (1 - a) Cos[12*Pi*b]}, {a, -1, 1}, {b, -1, 1}, 
       PlotStyle -> Directive[Brown], 
       MeshStyle -> {{Black, Thickness[0.001]}, {Black, 
          Thickness[0.001]}}, Axes -> False, Boxed -> False];
    K2 = {Blue, 
       Polygon[{{-50, 50, -3}, {50, 
          50, -3}, {50, -50, -3}, {-50, -50, -3}}]};
    K3 = {Black, Cylinder[{{15, 0, 0}, {15, 0, 15}}, .75]};
    K4 = {Black, Cylinder[{{-15, 0, 0}, {-15, 0, 15}}, .75]};
    K5 = {Black, Cylinder[{{0, 0, 0}, {0, 0, 30}}, .75]};
    Show[{Graphics3D[{K2, K3, K4, K5}], K1}]

This is what I used with the translation added:

    K1 = ParametricPlot3D[{(1 - 2 b) (7 + Cos[b]) Cos[
          8 Pi*a], (1 - a) (3 + Cos[4 b]) Sin[8*Pi*a], 
        4 a + (1 - a) Cos[12*Pi*b]}, {a, -1, 1}, {b, -1, 1}, 
       PlotStyle -> Directive[Brown], 
       MeshStyle -> {{Black, Thickness[0.001]}, {Black, 
          Thickness[0.001]}}, Axes -> False, Boxed -> False];
    K2 = {Blue, 
       Polygon[{{-50, 50, -3}, {50, 
          50, -3}, {50, -50, -3}, {-50, -50, -3}}]};
    K3 = {Black, Cylinder[{{15, 0, 0}, {15, 0, 15}}, .75]};
    K4 = {Black, Cylinder[{{-15, 0, 0}, {-15, 0, 15}}, .75]};
    K5 = {Black, Cylinder[{{0, 0, 0}, {0, 0, 30}}, .75]};
    Show[{Graphics3D[{K2, K3, K4, K5}], K1, Translate[{Graphics3D[{K2, K3, K4, K5}], K1}, {50, 0, 0}]}]

If anyone could add any clarification as to what I'm doing wrong, that would be greatly appreciated.

POSTED BY: Michael Kyzar
3 Replies
Posted 9 years ago

(I posted twice the answer, sorry.)

POSTED BY: Xavier Roy
Posted 9 years ago

Hi Michael,

In case one of your graphics primitive is defined with more than two options, such as for instance

K2 = {Blue, EdgeForm[],
        Polygon[{{-50, 50, -3}, {50, 50, -3}, {50, -50, -3}, {-50, -50, -3}}]};

(I added EdgeForm[] compared to your definition of K2 – this removes the black edge of the sea), the code

Graphics3D[Map[
    {First[#], Translate[Last[#], {50, 0, 0}]} &, {K2, K3, K4, K5}]

will not propagate the EdgeForm[] option. (EdgeForm[] is the second element of the list K2, and only its first and last element are considered.) In such a situation you can use directly

Graphics3D[Translate[{K2}, {50, 0, 0}]]

This way the graphics primitive is translated along with all its options. Using part of Craig's code, the alternative final code would read

Show[{Graphics3D[{K2, K3, K4, K5}], K1, 
  Graphics3D[Translate[{K2, K3, K4, K5}, {50, 0, 0}]], 
  K1 /. GraphicsComplex[points_, a__] :> GraphicsComplex[Map[# + {50, 0, 0} &, points], a]}]

which can be shorten into

Show[{Graphics3D[{K2, K3, K4, K5, Translate[{K2, K3, K4, K5}, {50, 0, 0}]}], K1, 
  K1 /. GraphicsComplex[points_, a__] :> GraphicsComplex[Map[# + {50, 0, 0} &, points], a]}]

Cheers, Xavier

POSTED BY: Xavier Roy

Hello MIchael, You can Translate something that is not a graphics primitive. But, there is a way around this:

Here, I use Map to only translate your primitives. Because your K1 is a GraphicsComplex, we can grab the points and then translate them the old-fashioned way:

Show[
 {Graphics3D[{K2, K3, K4, K5}], K1,
  Graphics3D[Map[
    {First[#], Translate[Last[#], {50, 0, 0}]} &, {K2, K3, K4, K5}]
   ],
  K1 /. GraphicsComplex[points_, a__] :>  
    GraphicsComplex[Map[# + {50, 0, 0} &, points], a]}]
POSTED BY: W. Craig Carter
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract