%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%%
%% Author:   Manuel Luque <manuel.luque27@gmail.com>
%%           Herbert Voß <hvoss@tug.org>   
%%
\csname PSTHyperboloidLoaded\endcsname
\let\PSTHyperboloidLoaded\endinput
% Requires some packages
\ifx\PSTricksLoaded\endinput\else \input pstricks \fi
\ifx\PSTXKeyLoaded\endinput\else  \input pst-xkey \fi
\def\fileversion{0.01}
\def\filedate{2026/06/04}
\message{`PSTHyperboloidLoaded' v\fileversion, \filedate}

\pstheader{pst-hyperboloid.pro}

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
\pst@addfams{pst-hyperboloid}

\pst@def{optionsHyperboloid}<%
         \pst@hyperboloid@base\space
          /vmax exch def
          /vmin exch def
          /umax exch def	
          /umin exch def
         /R \pst@hyperboloid@R def
         /H \pst@hyperboloid@h def
         /a@ \pst@hyperboloid@a def
         /DemiAxeFocal a@ def
         \pst@hyperboloid@ngrid
         /nv exch def
         /nu exch def
         /torsion \pst@HyperboloidB@AngleTorsion def
         /du umax umin sub nu div def
         /dv vmax vmin sub nv div def
%         /DemiAxeFocal R torsion 2 div cos mul def % rayon de l'�tranglement au milieu
         /DemiAxeNonFocal H 2 div R dup mul DemiAxeFocal dup mul sub sqrt div DemiAxeFocal mul def
         /Z0 {DemiAxeNonFocal X0 DemiAxeFocal div dup mul 1 sub sqrt mul} def
         /Y0 {DemiAxeFocal 1 X0 DemiAxeFocal div dup mul sub sqrt mul} def
         /Ymax {DemiAxeFocal H 2 DemiAxeNonFocal mul div dup mul 1 add X0 DemiAxeFocal div dup mul sub sqrt mul} def
         /ConeAsymptote DemiAxeFocal DemiAxeNonFocal div def
         /xMax DemiAxeNonFocal DemiAxeFocal mul DemiAxeNonFocal dup mul DemiAxeFocal dup mul sub sqrt div def
         /GrandAxe xMax 2 sqrt mul def
         /r@ {v dup mul R dup mul a@ dup mul sub mul a@ dup mul add sqrt} def
         /CalcX  {r@ u cos mul} def
         /CalcY  {r@ u sin mul} def
         /CalcZ  {v H mul 2 div} def
         >%
%
\define@key[psset]{pst-hyperboloid}{AngleTorsion}{\def\pst@HyperboloidB@AngleTorsion{#1 }} % angle de torsion
\define@key[psset]{pst-hyperboloid}{base}{\def\pst@hyperboloid@base{#1 }} %
\define@key[psset]{pst-hyperboloid}{ngrid}{\def\pst@hyperboloid@ngrid{#1 }} %
\define@key[psset]{pst-hyperboloid}{h}{\def\pst@hyperboloid@h{#1 }} %
\define@key[psset]{pst-hyperboloid}{R}{\def\pst@hyperboloid@R{#1 }} %
\define@key[psset]{pst-hyperboloid}{a}{\def\pst@hyperboloid@a{#1 }} %
\psset[pst-hyperboloid]{AngleTorsion=150,R=4,h=8,ngrid=36 20,base=0 360 -1 1,a=1} %
%
\def\psHyperboloid{\pst@object{psHyperboloid}}
% usage : \pstHyperboloid[options](x,y,z) %
\def\psHyperboloid@i{\@ifnextchar({\psHyperboloid@ii}{\psHyperboloid@ii(0,0,0)}}
\def\psHyperboloid@ii(#1,#2,#3){%
  \pst@killglue%
  \begingroup%
  \use@par%
\pstVerb{
    1 setlinejoin
    \tx@optionsHyperboloid
/sommets0 [
       vmin dv vmax dv add {% m�ridien apr�s m�ridien : 0 -> 360
        /v exch def
% les sommets le long d'un m�ridien
  /u umin def
    nu 1 add {
        [CalcX CalcY CalcZ]
  /u u du add def
     }repeat
       }for
       ] def
%
/faces0 { % avant l'ajout du centre
   0 1 nv 1 sub {
   /k1 exch def
k1 nu 1 add mul 1 nu k1 1 add mul k1 add 1 sub {/i exch def
    [
     i 1 add
     i
     i nu add 1 add
     i nu add 2 add
    ]
    } for
    } for}
    def
%
/Sommets % apr�s l'ajout du centre
[
   0 1 nv 1 sub {
   /k1 exch def
k1 nu 1 add mul 1 nu k1 1 add mul k1 add 1 sub {/i exch def
    [/pointsSommets [
     sommets0 i 1 add get aload pop
     sommets0 i get aload pop
     sommets0 i nu add 1 add get aload pop
     sommets0 i nu add 2 add get aload pop
    ] def
    pointsSommets aload pop pointsSommets isobarycentre3d]
    } for
    } for]
    def
%
/SOMMETS {
0 1 Sommets length 1 sub {/iL exch def
 Sommets iL get aload pop
 } for
 } def
%
/FACES {
 0 5 [SOMMETS] length 3 idiv 5 sub {/iF exch def
 [iF iF 1 add iF 4 add]
 [iF 1 add iF 2 add iF 4 add]
 [iF 2 add iF 3 add iF 4 add]
 [iF iF 4 add iF 3 add]
 } for
 } def
  }% fin du code ps
\psSolid[object=new,sommets=SOMMETS,faces=FACES](#1,#2,#3)%
  \endgroup%
  \ignorespaces%
}%
\definecolor{JaunePale}{rgb}{0.89 0.79 0.435}
\endinput
