[pstricks] tangent and orthogonal line

Martijn Frijlink m_frijlink at yahoo.com
Mon Apr 6 10:40:12 CEST 2009


Hi Herbert,

For me it would definitely useful. I tried to run your example but failed because my LaTeX installation (pdfeTeX) did not recognize

    \tx at ScreenCoor

and

    \tx at setlinejoin

Could it be a pdfTeX problem ?

Regards,
Martijn

--- On Mon, 4/6/09, Herbert Voss <Herbert.Voss at FU-Berlin.DE> wrote:

From: Herbert Voss <Herbert.Voss at FU-Berlin.DE>
Subject: [pstricks] tangent and orthogonal line
To: "Graphics with PSTricks" <pstricks at tug.org>
Date: Monday, April 6, 2009, 8:37 AM

Hi all,
I played a bit with tangent and orthogonal lines of a curve
given by several points and not a function. The following
example can draw a tangent or an othogonal line to a curve
defined by three points. Parameters are the coordinates of
the three points, the x value, and dx

If it may be useful, we can put it into one of the packages.

Herbert


\documentclass{minimal}
\usepackage{pst-3dplot}%  for the linear equation system solver
\makeatletter
\def\psOrthLine{\pst at object{psOrthLine}}
\def\psOrthLine at i(#1,#2)(#3,#4)(#5,#6)#7#8{%
  \begin at OpenObj%
  \addto at pscode{
    [[#1 dup dup mul exch 1 #2]
     [#3 dup dup mul exch 1 #4]
     [#5 dup dup mul exch 1 #6]]
    tx at 3DPlotDict begin SolveLinEqSystem end %
    /abc ED                % save the solution as array
    abc aload pop           % a b c on stack
    exch #7                 % a c b x
    mul add exch            % c+b*x a
    #7 dup mul mul add        % a*x^2+b*x+c
    /y0 ED            % save value
    abc aload pop pop exch % b a
    #7 mul 2 mul add       % b+2*a*x0
    neg 1 exch div         % mOrth
    #8 mul /dy ED          % mOrth*dx
    [
    #7 #8 add y0 dy add \tx at ScreenCoor % x0+dx y0 +dy
    #7 y0 \tx at ScreenCoor   % x0 y0
    /Lineto /lineto load def
    \ifshowpoints true \else false \fi
    \tx at setlinejoin        % 0 1 or 2           %
    \tx at Line }%            % load the pro function
  \end at OpenObj\ignorespaces}
\def\psTangentLine{\pst at object{psTangentLine}}
\def\psTangentLine at i(#1,#2)(#3,#4)(#5,#6)#7#8{%
  \begin at OpenObj%
  \addto at pscode{
    [[#1 dup dup mul exch 1 #2]
     [#3 dup dup mul exch 1 #4]
     [#5 dup dup mul exch 1 #6]]
    tx at 3DPlotDict begin SolveLinEqSystem end
    /abc ED
    abc aload pop    % a b c on stack
    exch #7          % a c b x
    mul add exch     % c+b*x a
    #7 dup mul mul add /y0 ED
    abc aload pop pop exch  % b a
    #7 mul 2 mul add        % b+2*a*x0=mTan
    dup                     % mTan mTan
    #8 mul /dy1 ED          % mTan*dx
    #8 neg mul /dy2 ED      % mTan*-dx
    [
    #7 #8 add y0 dy1 add \tx at ScreenCoor % x0+dx y0 +dy1
    #7 #8 sub y0 dy2 add \tx at ScreenCoor % x0-dx y0 +dy2
    /Lineto /lineto load def
    \ifshowpoints true \else false \fi
    \tx at setlinejoin                %
    \tx at Line }%
  \end at OpenObj\ignorespaces}
\makeatother
\begin{document}

\psset{unit=2}
\begin{pspicture}[showgrid=true](1,-1)(4,1)
  \pscurve[showpoints=true](2.1,-0.2)(2.5,0.2)(3.2,0.235)(3.8,-0.2)
  \psOrthLine[arrows=->,linecolor=red](2.5,0.2)(3.2,0.235)(3.8,-0.2){3}{0.1}

\psTangentLine[arrows=<->,linecolor=blue](2.5,0.2)(3.2,0.235)(3.8,-0.2){3}{0.5}
\end{pspicture}

\end{document}
_______________________________________________
PSTricks mailing list
PSTricks at tug.org
http://tug.org/mailman/listinfo/pstricks



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/pstricks/attachments/20090406/c15ea78f/attachment.html 


More information about the PSTricks mailing list