Drawing hexagonal prisms
Simmilar to:
Drawing spheres
I want to draw multiple 3D hexagonal cylinders like this one:
with different sizes and positions.
tikz-pgf floats asymptote
add a comment |
Simmilar to:
Drawing spheres
I want to draw multiple 3D hexagonal cylinders like this one:
with different sizes and positions.
tikz-pgf floats asymptote
This is called a hexagonal prism. en.wikipedia.org/wiki/Prism_(geometry)
– AndréC
12 mins ago
add a comment |
Simmilar to:
Drawing spheres
I want to draw multiple 3D hexagonal cylinders like this one:
with different sizes and positions.
tikz-pgf floats asymptote
Simmilar to:
Drawing spheres
I want to draw multiple 3D hexagonal cylinders like this one:
with different sizes and positions.
tikz-pgf floats asymptote
tikz-pgf floats asymptote
edited 11 mins ago
AndréC
8,82911447
8,82911447
asked yesterday
Ernesto IglesiasErnesto Iglesias
307
307
This is called a hexagonal prism. en.wikipedia.org/wiki/Prism_(geometry)
– AndréC
12 mins ago
add a comment |
This is called a hexagonal prism. en.wikipedia.org/wiki/Prism_(geometry)
– AndréC
12 mins ago
This is called a hexagonal prism. en.wikipedia.org/wiki/Prism_(geometry)
– AndréC
12 mins ago
This is called a hexagonal prism. en.wikipedia.org/wiki/Prism_(geometry)
– AndréC
12 mins ago
add a comment |
2 Answers
2
active
oldest
votes
Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
begin{document}
pgfkeys{/hexagonal prism/.cd,
rotation angle/.initial=0,
height/.initial=4,
diameter/.initial=2
}
tikzset{pics/.cd,
hexi/.style={code={
pgfmathsetmacro{myangle}{mod(pgfkeysvalueof{/hexagonal prism/rotation angle},60)}
pgfmathsetmacro{phieff}{(tdplotmainphi-mod(tdplotmainphi+690,60)+30)}
draw[fill=gray!60] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!20] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!10] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
ifdimtdplotmaintheta pt<90pt
draw[fill=gray!15] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
else
draw[fill=gray!85] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},0) -- cycle;
fi
}}}
tdplotsetmaincoords{70}{110}
begin{tikzpicture}[tdplot_main_coords,font=sffamily]
% path[tdplot_screen_coords,use as bounding box] (-3,-1) rectangle (3,5);
pic {hexi};
pic[shift={(5,0,0)},/hexagonal prism/height=3] {hexi};
end{tikzpicture}
end{document}
add a comment |
Using Asymptote and the unofficial polyhedron_js asymptote package (available here https://github.com/pivaldi/asymptote-packages) you can define easily such a cylinder and play with it.
Please find the code (assuming that you have polyhedron_js.asy)
import polyhedron_js;
// comment the following line for OpenGl
//settings.render=0;
settings.tex="pdflatex";
settings.outformat="pdf"; // for opacity
size(10cm);
currentprojection=perspective(7,6,4); //if you want perspectivic look
//currentprojection=orthographic(1,1,0.5); //if you want othographic look
currentlight=(1,1,2);
// currentlight=nolight;
polyhedron hexa_cyl;
guide hexa=polygon(6);
hexa_cyl[0]=(point(hexa,0).x,point(hexa,0).y,0);
for(int i=1;i<6;++i) hexa_cyl[0]=hexa_cyl[0]--(point(hexa,i).x,point(hexa,i).y,0);
hexa_cyl[0]=hexa_cyl[0]--cycle;
for(int i=0;i<6;++i)
{
hexa_cyl[i+1]=point(hexa_cyl[0],i)--point(hexa_cyl[0],(i+1)%6)--
(shift(0,0,1)*point(hexa_cyl[0],(i+1)%6))--(shift(0,0,1)*point(hexa_cyl[0],i))--cycle;
}
hexa_cyl[6]=shift(0,0,1)*hexa_cyl[0];
polyhedron p1={scale(1,1,3)*hexa_cyl};
polyhedron p2={shift(4,1,1)*rotate(60,(2,1,3))*hexa_cyl};
polyhedron p3={shift(-2,-2,-2)*rotate(90,(1,0,0))*scale(.5,.5,2)*hexa_cyl};
filldraw(p1,new pen{0.8green},op=0.9);
filldraw(p2,new pen{0.8blue},op=0.9);
filldraw(p3,new pen{0.8yellow},op=0.9);
and the result
Oh wow! That's really stunning!
– marmot
1 min ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473044%2fdrawing-hexagonal-prisms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
begin{document}
pgfkeys{/hexagonal prism/.cd,
rotation angle/.initial=0,
height/.initial=4,
diameter/.initial=2
}
tikzset{pics/.cd,
hexi/.style={code={
pgfmathsetmacro{myangle}{mod(pgfkeysvalueof{/hexagonal prism/rotation angle},60)}
pgfmathsetmacro{phieff}{(tdplotmainphi-mod(tdplotmainphi+690,60)+30)}
draw[fill=gray!60] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!20] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!10] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
ifdimtdplotmaintheta pt<90pt
draw[fill=gray!15] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
else
draw[fill=gray!85] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},0) -- cycle;
fi
}}}
tdplotsetmaincoords{70}{110}
begin{tikzpicture}[tdplot_main_coords,font=sffamily]
% path[tdplot_screen_coords,use as bounding box] (-3,-1) rectangle (3,5);
pic {hexi};
pic[shift={(5,0,0)},/hexagonal prism/height=3] {hexi};
end{tikzpicture}
end{document}
add a comment |
Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
begin{document}
pgfkeys{/hexagonal prism/.cd,
rotation angle/.initial=0,
height/.initial=4,
diameter/.initial=2
}
tikzset{pics/.cd,
hexi/.style={code={
pgfmathsetmacro{myangle}{mod(pgfkeysvalueof{/hexagonal prism/rotation angle},60)}
pgfmathsetmacro{phieff}{(tdplotmainphi-mod(tdplotmainphi+690,60)+30)}
draw[fill=gray!60] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!20] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!10] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
ifdimtdplotmaintheta pt<90pt
draw[fill=gray!15] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
else
draw[fill=gray!85] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},0) -- cycle;
fi
}}}
tdplotsetmaincoords{70}{110}
begin{tikzpicture}[tdplot_main_coords,font=sffamily]
% path[tdplot_screen_coords,use as bounding box] (-3,-1) rectangle (3,5);
pic {hexi};
pic[shift={(5,0,0)},/hexagonal prism/height=3] {hexi};
end{tikzpicture}
end{document}
add a comment |
Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
begin{document}
pgfkeys{/hexagonal prism/.cd,
rotation angle/.initial=0,
height/.initial=4,
diameter/.initial=2
}
tikzset{pics/.cd,
hexi/.style={code={
pgfmathsetmacro{myangle}{mod(pgfkeysvalueof{/hexagonal prism/rotation angle},60)}
pgfmathsetmacro{phieff}{(tdplotmainphi-mod(tdplotmainphi+690,60)+30)}
draw[fill=gray!60] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!20] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!10] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
ifdimtdplotmaintheta pt<90pt
draw[fill=gray!15] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
else
draw[fill=gray!85] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},0) -- cycle;
fi
}}}
tdplotsetmaincoords{70}{110}
begin{tikzpicture}[tdplot_main_coords,font=sffamily]
% path[tdplot_screen_coords,use as bounding box] (-3,-1) rectangle (3,5);
pic {hexi};
pic[shift={(5,0,0)},/hexagonal prism/height=3] {hexi};
end{tikzpicture}
end{document}
Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
begin{document}
pgfkeys{/hexagonal prism/.cd,
rotation angle/.initial=0,
height/.initial=4,
diameter/.initial=2
}
tikzset{pics/.cd,
hexi/.style={code={
pgfmathsetmacro{myangle}{mod(pgfkeysvalueof{/hexagonal prism/rotation angle},60)}
pgfmathsetmacro{phieff}{(tdplotmainphi-mod(tdplotmainphi+690,60)+30)}
draw[fill=gray!60] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!20] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
draw[fill=gray!10] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},0)
--({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle+phieff)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle+phieff)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
ifdimtdplotmaintheta pt<90pt
draw[fill=gray!15] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},pgfkeysvalueof{/hexagonal prism/height}) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},pgfkeysvalueof{/hexagonal prism/height}) -- cycle;
else
draw[fill=gray!85] ({pgfkeysvalueof{/hexagonal prism/diameter}*cos(0+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(0+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-60+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-60+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-120+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-120+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-180+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-180+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-240+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-240+myangle)},0) --
({pgfkeysvalueof{/hexagonal prism/diameter}*cos(-300+myangle)},{pgfkeysvalueof{/hexagonal prism/diameter}*sin(-300+myangle)},0) -- cycle;
fi
}}}
tdplotsetmaincoords{70}{110}
begin{tikzpicture}[tdplot_main_coords,font=sffamily]
% path[tdplot_screen_coords,use as bounding box] (-3,-1) rectangle (3,5);
pic {hexi};
pic[shift={(5,0,0)},/hexagonal prism/height=3] {hexi};
end{tikzpicture}
end{document}
edited yesterday
answered yesterday
marmotmarmot
97k4112213
97k4112213
add a comment |
add a comment |
Using Asymptote and the unofficial polyhedron_js asymptote package (available here https://github.com/pivaldi/asymptote-packages) you can define easily such a cylinder and play with it.
Please find the code (assuming that you have polyhedron_js.asy)
import polyhedron_js;
// comment the following line for OpenGl
//settings.render=0;
settings.tex="pdflatex";
settings.outformat="pdf"; // for opacity
size(10cm);
currentprojection=perspective(7,6,4); //if you want perspectivic look
//currentprojection=orthographic(1,1,0.5); //if you want othographic look
currentlight=(1,1,2);
// currentlight=nolight;
polyhedron hexa_cyl;
guide hexa=polygon(6);
hexa_cyl[0]=(point(hexa,0).x,point(hexa,0).y,0);
for(int i=1;i<6;++i) hexa_cyl[0]=hexa_cyl[0]--(point(hexa,i).x,point(hexa,i).y,0);
hexa_cyl[0]=hexa_cyl[0]--cycle;
for(int i=0;i<6;++i)
{
hexa_cyl[i+1]=point(hexa_cyl[0],i)--point(hexa_cyl[0],(i+1)%6)--
(shift(0,0,1)*point(hexa_cyl[0],(i+1)%6))--(shift(0,0,1)*point(hexa_cyl[0],i))--cycle;
}
hexa_cyl[6]=shift(0,0,1)*hexa_cyl[0];
polyhedron p1={scale(1,1,3)*hexa_cyl};
polyhedron p2={shift(4,1,1)*rotate(60,(2,1,3))*hexa_cyl};
polyhedron p3={shift(-2,-2,-2)*rotate(90,(1,0,0))*scale(.5,.5,2)*hexa_cyl};
filldraw(p1,new pen{0.8green},op=0.9);
filldraw(p2,new pen{0.8blue},op=0.9);
filldraw(p3,new pen{0.8yellow},op=0.9);
and the result
Oh wow! That's really stunning!
– marmot
1 min ago
add a comment |
Using Asymptote and the unofficial polyhedron_js asymptote package (available here https://github.com/pivaldi/asymptote-packages) you can define easily such a cylinder and play with it.
Please find the code (assuming that you have polyhedron_js.asy)
import polyhedron_js;
// comment the following line for OpenGl
//settings.render=0;
settings.tex="pdflatex";
settings.outformat="pdf"; // for opacity
size(10cm);
currentprojection=perspective(7,6,4); //if you want perspectivic look
//currentprojection=orthographic(1,1,0.5); //if you want othographic look
currentlight=(1,1,2);
// currentlight=nolight;
polyhedron hexa_cyl;
guide hexa=polygon(6);
hexa_cyl[0]=(point(hexa,0).x,point(hexa,0).y,0);
for(int i=1;i<6;++i) hexa_cyl[0]=hexa_cyl[0]--(point(hexa,i).x,point(hexa,i).y,0);
hexa_cyl[0]=hexa_cyl[0]--cycle;
for(int i=0;i<6;++i)
{
hexa_cyl[i+1]=point(hexa_cyl[0],i)--point(hexa_cyl[0],(i+1)%6)--
(shift(0,0,1)*point(hexa_cyl[0],(i+1)%6))--(shift(0,0,1)*point(hexa_cyl[0],i))--cycle;
}
hexa_cyl[6]=shift(0,0,1)*hexa_cyl[0];
polyhedron p1={scale(1,1,3)*hexa_cyl};
polyhedron p2={shift(4,1,1)*rotate(60,(2,1,3))*hexa_cyl};
polyhedron p3={shift(-2,-2,-2)*rotate(90,(1,0,0))*scale(.5,.5,2)*hexa_cyl};
filldraw(p1,new pen{0.8green},op=0.9);
filldraw(p2,new pen{0.8blue},op=0.9);
filldraw(p3,new pen{0.8yellow},op=0.9);
and the result
Oh wow! That's really stunning!
– marmot
1 min ago
add a comment |
Using Asymptote and the unofficial polyhedron_js asymptote package (available here https://github.com/pivaldi/asymptote-packages) you can define easily such a cylinder and play with it.
Please find the code (assuming that you have polyhedron_js.asy)
import polyhedron_js;
// comment the following line for OpenGl
//settings.render=0;
settings.tex="pdflatex";
settings.outformat="pdf"; // for opacity
size(10cm);
currentprojection=perspective(7,6,4); //if you want perspectivic look
//currentprojection=orthographic(1,1,0.5); //if you want othographic look
currentlight=(1,1,2);
// currentlight=nolight;
polyhedron hexa_cyl;
guide hexa=polygon(6);
hexa_cyl[0]=(point(hexa,0).x,point(hexa,0).y,0);
for(int i=1;i<6;++i) hexa_cyl[0]=hexa_cyl[0]--(point(hexa,i).x,point(hexa,i).y,0);
hexa_cyl[0]=hexa_cyl[0]--cycle;
for(int i=0;i<6;++i)
{
hexa_cyl[i+1]=point(hexa_cyl[0],i)--point(hexa_cyl[0],(i+1)%6)--
(shift(0,0,1)*point(hexa_cyl[0],(i+1)%6))--(shift(0,0,1)*point(hexa_cyl[0],i))--cycle;
}
hexa_cyl[6]=shift(0,0,1)*hexa_cyl[0];
polyhedron p1={scale(1,1,3)*hexa_cyl};
polyhedron p2={shift(4,1,1)*rotate(60,(2,1,3))*hexa_cyl};
polyhedron p3={shift(-2,-2,-2)*rotate(90,(1,0,0))*scale(.5,.5,2)*hexa_cyl};
filldraw(p1,new pen{0.8green},op=0.9);
filldraw(p2,new pen{0.8blue},op=0.9);
filldraw(p3,new pen{0.8yellow},op=0.9);
and the result
Using Asymptote and the unofficial polyhedron_js asymptote package (available here https://github.com/pivaldi/asymptote-packages) you can define easily such a cylinder and play with it.
Please find the code (assuming that you have polyhedron_js.asy)
import polyhedron_js;
// comment the following line for OpenGl
//settings.render=0;
settings.tex="pdflatex";
settings.outformat="pdf"; // for opacity
size(10cm);
currentprojection=perspective(7,6,4); //if you want perspectivic look
//currentprojection=orthographic(1,1,0.5); //if you want othographic look
currentlight=(1,1,2);
// currentlight=nolight;
polyhedron hexa_cyl;
guide hexa=polygon(6);
hexa_cyl[0]=(point(hexa,0).x,point(hexa,0).y,0);
for(int i=1;i<6;++i) hexa_cyl[0]=hexa_cyl[0]--(point(hexa,i).x,point(hexa,i).y,0);
hexa_cyl[0]=hexa_cyl[0]--cycle;
for(int i=0;i<6;++i)
{
hexa_cyl[i+1]=point(hexa_cyl[0],i)--point(hexa_cyl[0],(i+1)%6)--
(shift(0,0,1)*point(hexa_cyl[0],(i+1)%6))--(shift(0,0,1)*point(hexa_cyl[0],i))--cycle;
}
hexa_cyl[6]=shift(0,0,1)*hexa_cyl[0];
polyhedron p1={scale(1,1,3)*hexa_cyl};
polyhedron p2={shift(4,1,1)*rotate(60,(2,1,3))*hexa_cyl};
polyhedron p3={shift(-2,-2,-2)*rotate(90,(1,0,0))*scale(.5,.5,2)*hexa_cyl};
filldraw(p1,new pen{0.8green},op=0.9);
filldraw(p2,new pen{0.8blue},op=0.9);
filldraw(p3,new pen{0.8yellow},op=0.9);
and the result
answered 7 hours ago
O.G.O.G.
1,85059
1,85059
Oh wow! That's really stunning!
– marmot
1 min ago
add a comment |
Oh wow! That's really stunning!
– marmot
1 min ago
Oh wow! That's really stunning!
– marmot
1 min ago
Oh wow! That's really stunning!
– marmot
1 min ago
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473044%2fdrawing-hexagonal-prisms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This is called a hexagonal prism. en.wikipedia.org/wiki/Prism_(geometry)
– AndréC
12 mins ago