I would like to make different components of my 3D regions show in different colors (colours). Here are some dimensions for a bolt, washer and plate. I can make the individual components in different colors but when I assemble them (the last graphic) they are all in the same default color.
Len = 150/1000; (*length of plate *)
ht = 15/1000; (* height *)
wd = 80/1000; (* width *)
rh = 1/2 11/1000; (* hole radius *)
rb = 1/2 10/1000;(* bolt shaft radius *)
rwi = 1/2 (105/10)/1000; (* washer inner radius *)
rwo = 1/2 21/1000; (* washer outside radius *)
hw = 2/1000; (* washer thickness *)
rhd = 1/2 17/1000;(* head radius *)
Lh = (718/100)/1000;(* head length *)
reg1 = BoundaryDiscretizeRegion[
Cuboid[{-Len/2, -wd/2, 0}, {Len/2, wd/2, ht}],
MeshCellStyle -> Orange];(* plate *)
reg2 = BoundaryDiscretizeRegion[
Cylinder[{{0, 0, -ht}, {0, 0, 2 ht}}, rh]]; (* hole*)
reg3 = RegionDifference[reg1, reg2, MeshCellStyle -> {Darker[Orange]}]
reg4 = BoundaryDiscretizeRegion[
Cylinder[{{0, 0, 0}, {0, 0, ht + hw}}, rb]]; (* bolt shank *)
reg5 = BoundaryDiscretizeRegion[
Cylinder[{{0, 0, ht + hw}, {0, 0, ht + hw + Lh}},
rhd]]; (* bolt head *)
reg6 = RegionUnion[reg4, reg5, MeshCellStyle -> {Darker[Green]}]
reg7 = BoundaryDiscretizeRegion[
Cylinder[{{0, 0, ht}, {0, 0, ht + hw}}, rwo]]; (* washer *)
reg8 = BoundaryDiscretizeRegion[
Cylinder[{{0, 0, ht}, {0, 0, ht + hw}}, rwi]]; (* washer hole*)
reg9 = RegionDifference[reg7, reg8, MeshCellStyle -> {Darker[Yellow]}]
reg = RegionUnion[reg3, reg6, reg9]
How can I make each component (bolt, washer and plate) have different colors? Thanks
Edit
Chip Hurst makes the good suggestion that if it is just for display then Show
can be used
Show[reg3, reg6, reg9]
This is actually very useful. If I turn the plate over I can examine the quality of the clearance between the bolt and the hole.
Show
instead ofRegionUnion
. Also FYI if you usePlotTheme -> “Minimal”
the edges and points will be hidden. $\endgroup$Show
is a good one if I just wish to examine the assembly. Also, thanks for thePlotTheme
idea. $\endgroup$RegionUnion
. However, I could have built them using a different datum for each component. Then in order to assemble them you would have to apply translations and rotations so that they all come together properly. With the color added this makes for good CAD. $\endgroup$