3
\documentclass[tikz,border=15pt]{standalone}
\begin{document}
\begin{tikzpicture}[line join=round]
\def\a{3}
\draw[step=1,thin,gray!50] (0,0) grid (4*\a,2*\a);%Vẽ lưới
\draw (0:0)--++(90:1.5*\a)coordinate(A)--([turn]-159:\a)coordinate(B)--([turn]120:\a)coordinate(C)--(A);
\draw(B)--(C)--([turn]-125:\a)coordinate(D)--([turn]90:\a)coordinate(E)--([turn]90:\a)coordinate(F)--(C);
\draw(D)--(E)--([turn]-37:\a)coordinate(G)--([turn]72:\a)coordinate(H)--([turn]72:\a)coordinate(I)--([turn]72:\a)coordinate(J)--(E);
\draw (G)--(H)--([turn]-141:\a);
\end{tikzpicture}
\end{document}

enter image description here

My PSTricks's code

\documentclass[border=15pt,pstricks,12pt]{standalone}
\usepackage{pstricks-add}
\begin{document}
\def\a{3}
\begin{pspicture}[showgrid](0,0)(15,10)
\psline(0,0)(+0,1.5*\a)
\pnode(+0,1.5*\a){A} \uput[90](A){$A$}
\rput(A){%
\pnode(\a;-69){B} \uput[-90](B){$B$}
\pnode(\a;-9){C} \uput[90](C){$C$}
}
%
\pnode([nodesep=\a,angle=55]{B}C){D}
\uput[-90](D){$D$}
\pnode([nodesep=\a,angle=145]{B}C){F}
\uput[90](F){$F$}
\pnode([nodesep=\a,angle=90]{C}F){E}
\uput[-90](E){$E$}
%
\pnode([nodesep=\a,angle=143]{D}E){G}
\uput[-90](G){$G$}
\pnode([nodesep=\a,angle=108]{G}E){J}
\uput[120](J){$J$}
\pnode([nodesep=\a,angle=108]{E}J){I}
\uput[90](I){$I$}
\pnode([nodesep=\a,angle=108]{J}I){H}
\uput[40](H){$H$}
%
\psline(H)(H|0,0)(0,0)
\pspolygon(A)(B)(C)
\pspolygon(C)(D)(E)(F)
\pspolygon(E)(J)(I)(H)(G)
\end{pspicture}
\end{document}

enter image description here

Question:

What is the PSTricks equivalent for 'turn' in Tikz?

5

You can use the following point construction to get the same behavior as the TikZ's turn keyword does. The description is given as follows.

enter image description here

It is just one of four rarely-used point constructions in PSTricks. The remaining three are irrelevant for this question.

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-eucl}
\def\a{3 }
\begin{document}

\begin{pspicture}[showgrid,PointName=none,linecolor=red](\pscalculate{4*\a},\pscalculate{2*\a})
    \pnode(0,0){O}
    \pstGeonode[CurveType=polygon]
                        ([nodesep=\pscalculate{1.5*\a},angle=90]O){A}
                        ([nodesep=-\a,angle=-159]{O}A){B}
                        ([nodesep=-\a,angle=120]{A}B){C}
    \pstGeonode
                        ([nodesep=-\a,angle=-125]{B}C){D}
                        ([nodesep=-\a,angle=90]{C}D){E}
                        ([nodesep=-\a,angle=90]{D}E){F}
    \pspolygon(C)(D)(E)(F)
    \pstGeonode
                        ([nodesep=-\a,angle=-37]{D}E){G}
                        ([nodesep=-\a,angle=72]{E}G){H}
                        ([nodesep=-\a,angle=72]{G}H){I}
                        ([nodesep=-\a,angle=72]{H}I){J}
    \pspolygon(E)(G)(H)(I)(J)
\end{pspicture}
\end{document}

enter image description here

An important note for PSTricks' maintainer:

  • angle=\pscalculate{180+90} can be written as angle={!180 90 add}, but
  • nodesep=\pscalculate{1.5*\a} cannot be written as nodesep={!1.5 \a mul}
5

With turtle graphics:

  • lt : left,
  • rt : right,
  • fd : forward,
  • bk : back,
  • pu : pen up,
  • pd : pen down

\documentclass[border=15pt,pstricks]{standalone}
\usepackage{pst-turtle}
\def\a{3 }
\begin{document}

\begin{pspicture}[showgrid](12,6)
\psTurtle[linecolor=red,linewidth=1.5pt,linejoin=2]{turtle 0 setheading 
  90 lt \a 1.5 mul fd % first line
  159 rt \a fd 120 lt \a fd 120 lt \a fd % triangle
  pu \a bk pd % move
  115 lt \a fd 3 { 90 lt \a fd } repeat % square
  pu 90 lt \a fd 90 lt \a fd pd % move
  37 rt \a fd 4 { 72 lt \a fd } repeat % pentagon 
  pu 2 { 72 lt \a fd } repeat pd % move
  141 rt \a fd } % last line

\end{pspicture}
\end{document}

enter image description here

The package is not on CTAN (maybe next week), but available here: http://latex.userpage.fu-berlin.de/pst-turtle.zip

It is also possible to rotate nodes with \psRelNode

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pstricks-add}
\def\a{3 }
\begin{document}

\begin{pspicture}[showgrid,linecolor=red](12,6)
  \pnodes(0,0){O}(!0 \a 1.5 mul){A}\uput[90](A){A}
  \psRelNode[angle=21](A)(O){0.667}{B}\uput[-90](B){B}
  \psRelNode[angle=60](A)(B){1}{C}\uput[90](C){C}
  \pspolygon[showpoints](A)(B)(C)

  \psRelNode[angle=145](C)(B){1}{D}\uput[90](D){D}
  \psRelNode[angle=90](D)(C){1}{E}\uput[-90](E){E}
  \psRelNode[angle=90](E)(D){1}{F}\uput[-90](F){F}
  \pspolygon[showpoints](C)(D)(E)(F)

  \psRelNode[angle=145](E)(F){1}{G}\uput[-90](G){G}
  \psRelNode[angle=-108](G)(E){1}{H}\uput[0](H){H}
  \psRelNode[angle=-108](H)(G){1}{I}\uput[0](I){I}
  \psRelNode[angle=-108](I)(H){1}{J}\uput[100](J){J}
  \pspolygon[showpoints](E)(G)(H)(I)(J)
\end{pspicture}
\end{document}

enter image description here

  • I do not understand your problem! – Red-Cloud May 19 at 11:36

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.