2
$\begingroup$

I'm having an issue that is related to an old question (How do I plot a filled cylinder in 3D?), but it's an extension of it. The previous question details how to make 2D slices of a 3D region with filled objects. While I can make a Graphics3D image of what I need, the objects in the image are not 'regions' and the code won't work. Details are herein presented.

I have a 3D graphic of randomly oriented and placed rectangular prisms using Translate[Rotate[Cuboid[]]].

img = {FaceForm[], EdgeForm[], Cuboid[{0, 0, 0}, {50, 50, 50}]};
fiber1 = Translate[Rotate[Cuboid[{0, 0, 0}, {2, 2, 10}], 
 RandomReal[{0, Pi}], {RandomReal[], RandomReal[], 
 RandomReal[]}], {RandomReal[{5, 45}], RandomReal[{5, 45}], 
 RandomReal[{5, 45}]}];
fiber2 = Translate[
 Rotate[Cuboid[{0, 0, 0}, {2, 2, 10}], 
 RandomReal[{0, Pi}], {RandomReal[], RandomReal[], 
 RandomReal[]}], {RandomReal[{5, 45}], RandomReal[{5, 45}], 
 RandomReal[{5, 45}]}];
fiber3 = Translate[
 Rotate[Cuboid[{0, 0, 0}, {2, 2, 10}], 
 RandomReal[{0, Pi}], {RandomReal[], RandomReal[], 
 RandomReal[]}], {RandomReal[{5, 45}], RandomReal[{5, 45}], 
 RandomReal[{5, 45}]}];
fiber4 = Translate[
 Rotate[Cuboid[{0, 0, 0}, {2, 2, 10}], 
 RandomReal[{0, Pi}], {RandomReal[], RandomReal[], 
 RandomReal[]}], {RandomReal[{5, 45}], RandomReal[{5, 45}], 
 RandomReal[{5, 45}]}];
fiber5 = Translate[
 Rotate[Cuboid[{0, 0, 0}, {2, 2, 10}], 
 RandomReal[{0, Pi}], {RandomReal[], RandomReal[], 
 RandomReal[]}], {RandomReal[{5, 45}], RandomReal[{5, 45}], 
 RandomReal[{5, 45}]}];

fiberlist=Table[0,{6}];
fiberlist[[1]]=img;
fiberlist[[2]]=fiber1;
fiberlist[[3]]=fiber2;
fiberlist[[4]]=fiber3;
fiberlist[[5]]=fiber4;
fiberlist[[6]]=fiber5;
Graphics3D[fiberlist, Boxed -> False]

The code above generates a sample image of the ones that I use. Next, I want to create 2D slices of this image to export to another program. This is already completed in the above referenced question "How do I plot a filled cylinder in 3D?", but for completion's sake I've taken the code that I want to use and placed it here:

plots = Block[{reg}, 
 reg = Compile @@ {{x, y, z}, 
 Rest@RegionMember[RegionUnion @@ fiberlist, {x, y, z}]};
 Table[RegionPlot[reg[x, y, z], {x, 0, 50}, {y, 0, 50}], {z, 0, 50, 
 1}]];

If you want to see the list of 2D plots, go to the referenced question and copy the code given by Michael E2.

The issue is that, while Cuboid[] is a region by definition and will work in the above code, Translate[Rotate[Cuboid[]]] is not a region. I need a computationally efficient way to produce the same or an equivalent image as the one above. It must be relative to the same computational efficiency as the code above since the actual images I will be making can have hundreds of cuboids (if it takes 30 minutes per cuboid, that won't work, but 30 minutes for the entire image would be unfortunate but fine). I can't figure out how to do it. I've looked at RotationTransform[] with TranslationTransform[], but they aren't as intuitively obvious to me as Rotate[] and Translate[]. I've tried using RotationMatrix[] with the vector inside Cuboid[], i.e. rotating and translating the vector {{0,0,0},{2,2,10}} such that I get Cuboid["actual coordinates"], but my cuboids come out misshapen and distorted.

Any thoughts would be greatly appreciated!

$\endgroup$
4
$\begingroup$

while Cuboid[] is a region by definition and will work in the above code, Translate[Rotate[Cuboid[]]] is not a region

TransformedRegion may be useful, for example

fiberlist = Table[
   TransformedRegion[
     Cuboid[{0, 0, 0}, {2, 2, 10}]
     , 
     Composition[
      RotationTransform[RandomReal[{0, Pi}], {RandomReal[], RandomReal[], RandomReal[]}]
      ,
      TranslationTransform[{RandomReal[{5, 45}], RandomReal[{5, 45}], RandomReal[{5, 45}]}]
     ]
   ]
   , 
   {5}
];

VectorQ[fiberlist, RegionQ]

(* True *)

RegionPlot3D[fiberlist, Boxed -> False]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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