Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to use PSTricks to draw a line. However, I only have one point, but I know at which angle I want to draw the line, and how long I want it.

Is there some way to draw a line from a point (x,y) at a given angle, for a given length?

Are there any macro packages that would help me out here?

share|improve this question
    
The title may be better phrased as "In PSTricks, how to draw a line from a point at a given slope angle?" –  xport Dec 25 '10 at 16:25

4 Answers 4

PSTricks has polar coordinates: see page 13 in the manual.

\SpecialCoor
\psline[linewidth=2pt](4;50)(0,0)(4;10)
\psarc[arcsepB=2pt]{->}{3}{10}{50}

produces alt text

which will require that you move the coordinate system so that the origin is at the point you have.

Otherwise, you could use the more elaborate options of \SpecialCoor, listed at pp. 72. specifically the ([par]node) notation which describes

The position relative to node determined using the angle, nodesep and offset parameters. E.g., ([angle=45]A),

but requires that you define the current point you have as a named node (not so painful).

Thus:

\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}


\begin{document}
\begin{pspicture}(4,5)
\pnode(1,1){Y}
\SpecialCoor
\psline(Y)([angle=30,nodesep=2]Y)
\end{pspicture}
\end{document}

creates: alt text

share|improve this answer

it is possible to draw a vectorline which always starts at the last current point. It needs only one coordinate the other one is the current point. All points are internally saved as nodes, which can be used later.

alt text

\documentclass{article}

\usepackage{pstricks-add,multido}

\begin{document}

\begin{pspicture}[showgrid,linewidth=1pt](10,10.4)
 \psStartPoint[A](1,1)% nodes have the base name A
 \psVector(3;30)\psVector(4;60)\psVector[linecolor=red](3;10)
 \psVector[linestyle=dashed](4;110)
 \psline{->}(A0)(A4)

 \psStartPoint[B](1,1)\psset{markAngle}% nodes have the base name B
 \psVector[linestyle=dashed](4;110)
 \psVector[linecolor=red](3;10)
 \psVector(4;60)\psVector(3;30)

 \multido{\iA=0+1}{5}{\uput[0](A\iA){A\iA}\uput[180](B\iA){B\iA}}
 \end{pspicture}

\end{document}
share|improve this answer
    
How to make a series of \psVectors enclosed by \pscustom still work? In my attempt, all the tails become at the same point rather than what they are supposed to be. –  Who is crazy first Jul 18 '12 at 11:22
    
I do not really understand what you want to achieve. However, I cannot test anything in the next few weeks, I have no running TeX system –  Herbert Jul 18 '12 at 14:23
    
Actually I want to use \psVectors inside the \pscustom for my answer here. But they do not work in \pscustom. As a replacement, I used \rlineto and it works. –  Who is crazy first Jul 18 '12 at 14:34
    
there is absolutely no need for using \psVector inside a \pscustom ... –  Herbert Aug 9 '12 at 10:35

you need to know a little bit of postscript language and reverse polish notation:

\documentclass{article}
\usepackage{pstricks-add}
\usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm]{geometry}
\begin{document}
\begin{figure}[h]
\def\xA{1}
\def\yA{2}
\def\Length{4}
\def\Angle{45} % angles are in degrees
\begin{pspicture}(0,0)(6,6)
\psgrid
% define point A
\cnode*(\xA,\yA){0pt}{A}%
% define point B 
\cnode*(! \Length\space \Angle\space cos mul \xA\space add \Length\space \Angle\space  sin mul \yA\space add){0pt}{B}%
% draw line
\psline[linewidth=1pt](A)(B)%
\end{pspicture}
\end{figure}
\end{document} 
share|improve this answer
    
In TikZ, this is as simple as dropping into polar coordinates for some part of the path: \tikz \draw (0,0) -- (1,1) -- ++(canvas polar cs:angle=90,radius=1cm) -- +(1,0); or, concisely, \tikz \draw (0,0) -- (1,1) -- ++(90:1cm) -- +(1,0);. Is there not a similar way to use polar coordinates with PStricks that doesn't involve manually invoking cos and sin? –  Sharpie Oct 7 '10 at 5:26
    
it is never bad to know a little bit more than the proposed "easy" techniques. –  pluton Oct 7 '10 at 12:08

I think the simplest method is to use \SpecialCoor, polar coordinate form, and origin option as illustrated in the following example.

\documentclass{article}
\usepackage{pstricks}
\begin{document}

\begin{pspicture}[showgrid=true](5,5)
\SpecialCoor
% draw a line from a point (1,2) at angle 45 degrees and of length 3 unit. 
\psline[origin={1,2}](3;45)
\end{pspicture}
\end{document}

Output:

alt text


Edit 1:

To make sure the line length is 3 cm, I draw a red circle of radius 3 cm.

alt text

share|improve this answer
    
I believe my answer is the simplest one. :-) –  xport Dec 26 '10 at 19:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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