Graphics, Figures & TablesPSTricks | 2D Analogue for drawCoor?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | 2D Analogue for drawCoor?

Post by svend_tveskaeg »

Hi all.

Is there an option similar to drawCoor from the pst-3dplot package for 2D plots.

What I would like to do is to highlight the coordinates for a point i R^2 by drawing a dotted (or dashed) line from the point and perpendicular onto each axes. This is of course not difficult to do manually, but an option to do it automatic would be nice.

Thank you in advance!
Last edited by svend_tveskaeg on Fri Oct 05, 2012 10:10 pm, edited 4 times in total.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | 2D Analogue for drawCoor?

Post by CrazyHorse »

svend_tveskaeg wrote: Is there an option similar to drawCoor from the pst-3dplot package for 2D plots.

What I would like to do is to highlight the coordinates for a point i R^2 by drawing a dotted (or dashed) line from the point and perpendicular onto each axes. This is of course not difficult to do manually, but an option to do it automatic would be nice.
it is simple to write an own macro \psDots(#1,#2) which draws the coordinates.
A _little bit_ more complicated is an optional argument. Have a look at pstricks.tex how \psTextFrame is defined.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: PSTricks | 2D Analogue for drawCoor?

Post by svend_tveskaeg »

Thank you, Herbert.

I have only two such points in the entire document so I will not define my own macro for this.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | 2D Analogue for drawCoor?

Post by svend_tveskaeg »

I now see that I actually have some more points so here is a possible solution.

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}

\newcommand{\intersection}[2]{%
  \psline[linestyle=dotted](0,#2)(#1,#2)(#1,0)
  \psdot(#1,#2)
}

\begin{document}

\begin{figure}
 \centering
  \begin{pspicture}(-1.5,-0.5)(5.8,11)
   \psset{algebraic}
    \psaxes{->}(0,0)(-1.5,-0.5)(5.5,10.5)[$x$,0][$y$,90]
    \psplot[linewidth=1.25pt,linecolor=blue]{-1.2}{5.2}{x^2-4*x+4}
    \rput(4.15,6){$p$}
    \psplot[linewidth=1.25pt,linecolor=red]{-1.2}{5.5}{x+4}
    \rput(2,6.5){$m$}
    \intersection{5}{9}
  \end{pspicture}
\end{figure}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | 2D Analogue for drawCoor?

Post by svend_tveskaeg »

I have assumed that the \psaxes intersect at (0,0).

@Herbert (or others): If I would like to

(1) have the \psaxes intersectinon at some other point than (0,0), and
(2) give some options to the line color and dot color

how do I do modity \intersection to accomplish that?

I do not quite understand how to do this after I had a look at pstricks.tex. It is probably a rather simple task but I cannot figure it out. :(
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | 2D Analogue for drawCoor?

Post by CrazyHorse »

svend_tveskaeg wrote:I have assumed that the \psaxes intersect at (0,0).

@Herbert (or others): If I would like to

(1) have the \psaxes intersectinon at some other point than (0,0), and
(2) give some options to the line color and dot color

how do I do modity \intersection to accomplish that?

I do not quite understand how to do this after I had a look at pstricks.tex. It is probably a rather simple task but I cannot figure it out. :(

Code: Select all

\documentclass{article}
\usepackage{pstricks-add}

\makeatletter
\def\psDot{\pst@object{psDot}}
\def\psDot@i(#1){{%
    \addbefore@par{linestyle=dotted}
    \use@par
    \psline({0,0}|#1)(#1)(#1|{0,0}) % (x,y | x,y) x from 1st, y from 2nd
    \psdot(#1)
}}
\makeatother

\begin{document}

\begin{figure}
 \centering
  \begin{pspicture}(-1.5,-0.5)(5.8,11)
   \psset{algebraic}
    \psaxes{->}(0,0)(-1.5,-0.5)(5.5,10.5)[$x$,0][$y$,90]
    \psplot[linewidth=1.25pt,linecolor=blue]{-1.2}{5.2}{x^2-4*x+4}
    \rput(4.15,6){$p$}
    \psplot[linewidth=1.25pt,linecolor=red]{-1.2}{5.5}{x+4}
    \rput(2,6.5){$m$}
    \psDot(5,9)
    \psDot[linestyle=dashed,linecolor=blue](4,4)
  \end{pspicture}
\end{figure}

\end{document}
Attachments
xx.png
xx.png (13.17 KiB) Viewed 4785 times
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: PSTricks | 2D Analogue for drawCoor?

Post by svend_tveskaeg »

Perfect!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | 2D Analogue for drawCoor?

Post by svend_tveskaeg »

I have just found section 14.1 of the pst-plot manual. :D
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply