4

My picture uses a bunch of irregular quadrangles but there is no polygon macro in pst-3dplot

Is there a way to emulate the basic pstricks macro \pspolygon(a,b)(c,d)... in pst-3dplot?

I know I can just output four \pstThreeDLines in succession but there wouldn't be any miter joining as each one is an independant path. An added bonus would be the capacity to fill the path with an arbitrary color.

I thought about building the quadrangles out of two or four pstThreeDTriangles (which alows filling) but I don't think that helps with the stroking of the edges (which would still require stroking line by line)

I have a feeling this requires some hacking and I have tried to dig into the package's *.pro and *.tex files to have look under the hood but it's a jumble of mess. The postscript I can handle, but the TeX macro hell is still an incomprehensible jungle to me

\documentclass{book}
\usepackage{pstricks}
\usepackage{pst-3dplot}
\begin{document}%
\begin{pspicture}(-5,-5)(5,5)%
% I would need a macro that looks like the following
\pstThreeDQuad[options](p1)(p2)(p3)(p4)%
% but because this looks like a full blown
% project for the package maintainers
% I would rather any other solution
% including injecting postscript directly
\end{pspicture}%
\end{document}

I'm not afraid of PostScript, but I have very little handling of TeX. If I could decypher a way to inject my own postscript into a pspicture without breaking anything (while still making use of pst-3dplot environment settings) I wouldn't be asking this question (or I would answer it myself)


Updated for sharing

Thanks to the help I'll leave this nice result as a demonstration of the power of working with quads.

Stokes?

This looks like solides3d but is 3dplot and compiles in an instant

  • Welcome to TeX.SX! It is easier to help you if you add a minimal working example that takes the form \documentclass{...}\usepackage{....}\begin{document}...\end{document}. If possible, it should compile and have the minimum amount of code needed to illustrate your problem. This makes it much easier for people to troubleshoot your problem - and much more likely that they will! In this case having a list of example points would be invaluable. – Andrew Aug 16 '15 at 21:33
  • There is no MWE because this is an abstract problem that needs an abstracted solution. I'll add one just so it's easier to start a blank document – hanzo2001 Aug 17 '15 at 1:11
  • If you really need a \pstThreeDPolygon more than once I can extend the package. – user2478 Aug 18 '15 at 18:19
  • @Herbert wow... only if you have time to spare. But regardless of wether it's added or not, probably the most important thing is the documentation around it. As for my project, I think I can manage enough with quadrangles in the current scheme of things. – hanzo2001 Aug 18 '15 at 20:26
2

One possible approach is to create a macro \pstThreeDQuad[<options>](<1>)(<2>)(<3>)(<4>) that sets a 2D-node for each of the 3D-nodes <1>, <2>, <3> and <4>. Then, just set a regular 2D-polygon using \pstpolygon:

enter image description here

\documentclass{article}

\usepackage{pst-3dplot,xparse}

\NewDocumentCommand{\pstThreeDQuad}{O{} r()r()r()r()}{%
  \pstThreeDPut(#2){\pnode{A}}%
  \pstThreeDPut(#3){\pnode{B}}%
  \pstThreeDPut(#4){\pnode{C}}%
  \pstThreeDPut(#5){\pnode{D}}%
  \pspolygon[#1](A)(B)(C)(D)%
}

\begin{document}

\begin{pspicture}(-2,-1.25)(1,2.25)
  \SpecialCoor
  \psset{Alpha=60,Beta=30}
  \pstThreeDCoor[linecolor=blue,%
    xMin=-1,xMax=2,yMin=-1,yMax=2,zMin=-1,zMax=2]
  \pstThreeDDot[drawCoor=true](1,0.5,1.25)

  \pstThreeDQuad[linecolor=red,fillcolor=blue!15!white,fillstyle=solid](1,1,1)(2,2,2)(-1,0,3)(3,0,-2)
\end{pspicture}

\end{document}
  • This is amazing! You just made me read through xparse documentation (which I had not done yet because it was not included yet) and revisit the documentation of both pst-3dplot (p28) and pstricks (p60). Sticking these three things together just blew my mind. There is a very lackluster content around both these features. I hope Herbert sees this and adds the content of this solution to the documentation as a great example – hanzo2001 Aug 17 '15 at 10:13
  • Is it possible to introduce rawcoordinates (pscode). I seem to be getting an Use of raw@@coor doesn't match its definition error – hanzo2001 Aug 17 '15 at 10:36
3

It makes no real sense to define a new macro because it is a simple \pstThreeDLine with the same start and end point. However, if you really need a new macro then define it this way:

\documentclass{article}
\usepackage{pst-3dplot}
\def\pstThreeDQuad#1(#2)(#3)(#4)(#5){\pstThreeDLine#1(#2)(#3)(#4)(#5)(#2)}
\begin{document}

    \begin{pspicture}(-2,-1.25)(1,2.25)
    \psset{Alpha=60,Beta=30}
    \pstThreeDCoor[linecolor=blue,xMin=-1,xMax=2,yMin=-1,yMax=2,zMin=-1,zMax=2]
    \pstThreeDDot[drawCoor=true](1,0.5,1.25)
%   \pstThreeDLine[linecolor=red,fillcolor=blue!30!white,
%      fillstyle=solid,opacity=0.5](1,1,1)(2,2,2)(-1,0,3)(3,0,-2)(1,1,1)
    \pstThreeDQuad[linecolor=red,fillcolor=blue!30!white,
    fillstyle=solid,opacity=0.5](1,1,1)(2,2,2)(-1,0,3)(3,0,-2)
    \end{pspicture}

\end{document}

enter image description here

  • Well that was easy... – Werner Aug 18 '15 at 18:28
  • Just goes to show how important it is to know TeX. Is there a substantial difference between using Werner's solution and yours? – hanzo2001 Aug 18 '15 at 20:30
  • yes, I do not use xparse which is overkill here – user2478 Aug 19 '15 at 6:00

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.