[pstricks] How can I skip the invalid points when using \parametricplot?

廖雄飞 liaofei1128 at 163.com
Wed Dec 11 11:42:52 CET 2019


Hi, all:


Now I want to draw the Weierstrass elliptic curve as following:
$$y^2+ay=x^3+bx^2+cxy+dx+e$$
where a,b,c,d,e are coefficients can be input by parameters.


I need to call \parametricplot twice to draw the following two branches:
x(t) = t
y(t) = 1/2[(ct-a)+sqrt((ct-a)^2+4(t^3+bt^2+dt+e))]
and
x(t) = t
y(t) = 1/2[(ct-a)-sqrt((ct-a)^2+4(t^3+bt^2+dt+e))]


So I define a new command \pstEllipticCurve as following:


%% \pstEllipticCurve[Options]{a,b,c,d,e}{t1}{t2}
%% draw the elliptic curve $y^2+ay=x^3+bx^2+cxy+dx+e$ from t1 to t2.
%% Parameters:
%% #1 -> options
%% #2..#6 -> [input] the coefficients of elliptic curve
%% #7 -> [input] draw the elliptic curve from t1 to t2.
%% #8 -> [input] draw the elliptic curve from t1 to t2.
\def\pstEllipticCurve{\@ifnextchar[\Pst at EllipticCurve{\Pst at EllipticCurve[]}}
\def\Pst at EllipticCurve[#1](#2,#3,#4,#5,#6)#7#8{%
  \begingroup
    \psset{#1}%
    \parametricplot{#7}{#8}{%
       % a, b, c, d, e, t
       #2 #3 #4 #5 #6 t
       0 index 4 index mul 6 index sub % cx-a
       1 index 6 index add 2 index mul % (x+b)x
       4 index add 2 index mul % ((x+b)x+d)x
       3 index add % ((x+b)x+d)x+e
       4 mul % 4(((x+b)x+d)x+e)
       1 index dup mul add
       dup 0 lt {
         pop pop pop pop pop pop pop pop t 0
       } {
         sqrt 1 index add 2 div
         exch pop 7 2 roll pop pop pop pop pop
       } ifelse
    }%
    \parametricplot{#7}{#8}{%
       % a, b, c, d, e, t
       #2 #3 #4 #5 #6 t
       0 index 4 index mul 6 index sub % cx-a
       1 index 6 index add 2 index mul % (x+b)x
       4 index add 2 index mul % ((x+b)x+d)x
       3 index add % ((x+b)x+d)x+e
       4 mul % 4(((x+b)x+d)x+e)
       1 index dup mul add
       dup 0 lt {
         pop pop pop pop pop pop pop pop t 0
       } {
         sqrt 1 index exch sub 2 div
         exch pop 7 2 roll pop pop pop pop pop
       } ifelse
    }%
  \endgroup%
}%


I just push the point (t,0) to the stack if the sqrt operand less then zero, which will cause parametricplot draw a unexpected line on the x-axis,
the output pdf file is attached.


The test code as following:


\begin{pspicture}[showgrid=true](0,0)(4,4)
% y^2=x^3-3x+3
\pstEllipticCurve[linecolor=red](0,0,0,-3,3){-3}{3}
\psplotImp[linecolor=blue!30](-10,-10)(10,10){ x dup dup mul mul -3 x mul add y dup mul sub 3 add }
\end{pspicture}


So the question is, how can I skip the invalid points when using \parametricplot? 


I have an idea is to push a string (nan) into the stack and then modify the macro \parametricplot to check the type of value and don't draw them out.
but I can not modify \parametricplot by myself to archive this function. 


first, push a string (nan) into the stack in the postscript code where I call \parametricplot:
        dup 0 lt {
           pop pop pop pop pop pop pop pop t (nan)
        } {
          sqrt 1 index add 2 div
          exch pop 7 2 roll pop pop pop pop pop
        } ifelse


then try to check the type of value y in \parametricplot: 
     /xy {
         \ifPst at algebraic F at pstplot \else #5 \fi
         dup type (realtype) ne { % if y is not a real number
           pop pop false
        } {
          \pst at number\psyunit mul exch
          \pst at number\psxunit mul exch
          true
        } ifelse
     } def
and modify the code when we use xy to check the last value on stack is false or true.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/pstricks/attachments/20191211/10d9fe12/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output.pdf
Type: application/pdf
Size: 80142 bytes
Desc: not available
URL: <https://tug.org/pipermail/pstricks/attachments/20191211/10d9fe12/attachment-0001.pdf>


More information about the PSTricks mailing list