%%HP: T(3)A(D)F(.);
@ PLT3D by Dave Jansen
DIR
  SFACE
    \<< SPAR OBJ\->
DROP 0 { } \-> xa xb
xi ya yb yi theta
phi p z h v d flg
      \<< RCLF 'flg'
STO -20 -21 -22 SF
CF CF RAD ya yb
        FOR J J 'Y'
STO xa xb
          FOR I I
'X' STO DEPTH 'd'
STO
            IFERR
EQ \->NUM
            THEN
DEPTH d - DROPN 0
            END
            IF DUP
TYPE 1 ==
            THEN
DROP 0
            END yi
          STEP xi
        STEP yb ya
- ABS 1 + xb xa -
ABS 1 + 2 \->LIST
\->ARRY 'TOPO' STO {
X Y } PURGE DEG -20
-21 -22 CF SF SF
'flg' RCL STOF
TRACE
      \>>
    \>>
  TRACE
    \<< SPAR OBJ\->
DROP { } \-> xa xb xi
ya yb yi theta phi
p z h v flg
      \<< 0 0 0 0 0 \->
cphi sphi ctheta
stheta prv
        \<< RCLF
'flg' STO 64 STWS
PICT PURGE { # 0d
# 0d } PVIEW AXIS
RAD theta \pi * 180 /
\->NUM DUP SIN
'stheta' STO COS
'ctheta' STO phi \pi
* 180 / \->NUM DUP
SIN 'sphi' STO COS
'cphi' STO ya yb
          FOR j j
cphi * xa ctheta *
- h * 65 + 0 RND
# 1d * 63 j NEG
sphi * xa stheta *
- v * 31 + 0 RND
TOPO 1 j ya - yi *
1 + 2 \->LIST GET
            IF p 0
\=/
            THEN
              IF
DUP DUP z < p 0 >
AND SWAP z > p 0 <
AND OR
              THEN
DROP z
              END
            END + -
# 1d * 2 \->LIST
'prv' STO 1 xa + xb
            FOR i
prv j cphi * i
ctheta * - h * 65 +
0 RND # 1d * 63 j
NEG sphi * i stheta
* - v * 31 + 0 RND
TOPO i xa - xi * 1
+ j ya - yi * 1 + 2
\->LIST GET
              IF p
0 \=/
              THEN
IF DUP DUP z < p 0
> AND SWAP z > p 0
< AND OR
THEN DROP z
END
              END +
- # 1d * 2 \->LIST
DUP 'prv' STO LINE
xi
            STEP yi
          STEP xa
xb
          FOR i ya
cphi * i ctheta * -
h * 65 + 0 RND # 1d
* 63 ya NEG sphi *
i stheta * - v * 31
+ 0 RND TOPO i xa -
xi * 1 + 1 2 \->LIST
GET
            IF p 0
\=/
            THEN
              IF
DUP DUP z < p 0 >
AND SWAP z > p 0 <
AND OR
              THEN
DROP z
              END
            END + -
# 1d * 2 \->LIST
'prv' STO 1 ya + yb
            FOR j
prv j cphi * i
ctheta * - h * 65 +
0 RND # 1d * 63 j
NEG sphi * i stheta
* - v * 31 + 0 RND
TOPO i xa - xi * 1
+ j ya - yi * 1 + 2
\->LIST GET
              IF p
0 \=/
              THEN
IF DUP DUP z < p 0
> AND SWAP z > p 0
< AND OR
THEN DROP z
END
              END +
- # 1d * 2 \->LIST
DUP 'prv' STO LINE
yi
            STEP xi
          STEP DEG
PICT RCL 'GRPH' STO
          DO
          UNTIL KEY
          END DROP
        \>> 'flg' RCL
STOF
      \>>
    \>>
  AXIS
    \<< SPAR OBJ\->
DROP { } \-> xa xb xi
ya yb yi theta phi
p z h v flg
      \<< RCLF 'flg'
STO DEG { # 65d
# 32d } DUP DUP {
# 65d # 0d } LINE
10 h * theta COS *
NEG 65 + 0 RND # 1d
* 63 10 v * theta
SIN * NEG 31 + - 0
RND # 1d * 2 \->LIST
LINE 10 h * phi COS
* 65 + 0 RND # 1d *
63 10 v * phi SIN *
NEG 31 + - 0 RND
# 1d * 2 \->LIST LINE
'flg' RCL STOF
      \>>
    \>>
  SPAR { -5 5 1 -5
5 1 30 45 0 0 5 3 }
  EQ 'Y^2-X^2'
END
