summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-01-18 23:43:19 +0000
committerKarl Berry <karl@freefriends.org>2010-01-18 23:43:19 +0000
commite65c74e7551529b3db597eef51915ea683e96e7e (patch)
treec1595910d5ae13fb4718e353a6b348bf23daa9e3 /Master/texmf-dist/tex
parent45919681c5a1d4dd078abbabac51a5de84aa75b2 (diff)
new tikz package tikz-3dplot (18jan10)
git-svn-id: svn://tug.org/texlive/trunk@16779 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/latex/tikz-3dplot/tikz-3dplot.sty666
1 files changed, 666 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/tikz-3dplot/tikz-3dplot.sty b/Master/texmf-dist/tex/latex/tikz-3dplot/tikz-3dplot.sty
new file mode 100644
index 00000000000..819e8394fd4
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/tikz-3dplot/tikz-3dplot.sty
@@ -0,0 +1,666 @@
+%% tikz-3dplot.sty
+%% Copyright 2010 Jeffrey D. Hein
+%
+% 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.
+% The latest version of this license is in
+% http://www.latex-project.org/lppl.txt
+% and version 1.3 or later is part of all distributions of LaTeX
+% version 2005/12/01 or later.
+%
+% This work has the LPPL maintenance status `maintained'.
+%
+% The Current Maintainer of this work is Jeffrey D. Hein.
+%
+% This work consists of the files 3dplot.sty and 3dplot_documentation.tex
+
+%Description
+%-----------
+
+%tikz-3dplot.sty - package for plotting three dimensional axes and coordinates in TikZ. The user can specify orientation of the display, and also define rotated coordinate systems within the 3d display coordinate system.
+
+%Created 2009-11-07 by Jeff Hein. Last updated: 2010-01-17
+%----------------------------------------------------------
+
+%Requirements
+%------------
+%This requires the tikz package.
+
+%Update Notes
+%------------
+
+%2009-11-07: Created package from previous scratch work
+%2009-11-18: Added a few macros for storing user-specified coordinate frame angles. Useful for commands which would like to know what the current display perspective is.
+%2009-11-21: Added spherical polar parametric surface plotting functionality with the \tdplotsphericalsurfaceplot command.
+%2009-12-03: Fixed the range checking for polar parametric plotting. It should now behave better around the range \phi = 0
+%2010-01-17: renamed the package to tikz-3dplot.
+
+%TODO list
+%---------
+
+%TODO: figure out how to work in a variable scope that doesn't interfere with other packages
+%TODO: find a way to check if TikZ is loaded, and give a compile error if necessary
+%TODO: find a way to use predefined coordinates in rotated or translated coordinate frames, instead of just literal coordinates
+%TODO: generalize matrix math if such a package exists
+%TODO: look into using TikZ spherical polar coordinates explicitly to streamline coordinate definitions.
+
+\RequirePackage{pgf}
+\RequirePackage{ifthen}
+
+%Style definitions and includes
+%------------------------------
+\usetikzlibrary{calc,3d}
+
+\tikzset{tdplot_screen_coords/.style={x={(1 cm,0 cm)},y={(0 cm, 1 cm)},z={(-1 cm, -1 cm)}}}%
+
+\pgfmathsetmacro{\lowerphi}{0}
+\pgfmathsetmacro{\upperphi}{360}
+\pgfmathsetmacro{\lowertheta}{0}
+\pgfmathsetmacro{\uppertheta}{180}
+
+
+%Commands
+%--------
+
+%\tdplotsinandcos{sin}{cos}{theta}
+%determines the sin and cos of the specified angle (in degrees).
+%#1: returns sin(#3)
+%#2: returns cos(#3)
+%#3: user-specified angle
+\newcommand{\tdplotsinandcos}[3]{%
+\pgfmathsetmacro{#1}{sin(#3)}%
+\pgfmathsetmacro{#2}{cos(#3)}%
+}
+
+%\tdplotmult{result}{multiplicand}{multiplicator}
+%determines the multiplication of specified values.
+%#1: returns #2*#3
+%#2: user-specified multiplicand
+%#3: user-specified multiplicator
+\newcommand{\tdplotmult}[3]{%
+\pgfmathsetmacro{#1}{#2*#3}%
+}
+
+%\tdplotdiv{result}{dividend}{divisor}
+%determines the division of specified values.
+%#1: returns #2/#3
+%TODO: handle divide by zero?
+%#2: user-specified dividend
+%#3: user-specified divisor
+\newcommand{\tdplotdiv}[3]{%
+\pgfmathsetmacro{#1}{#2/#3}%
+}
+
+%\tdplotcheckdiff{first value}{right value}{tolerance}{true code}{false code}
+%compares two values to within specified tolerance. Executes either the true code or false code depending on the comparison result.
+%#1: value 1 to compare
+%#2: value 2 to compare
+%#3: tolerance
+%#4: true condition result
+%#5: false condition result
+\newcommand{\tdplotcheckdiff}[5]{%
+%
+ \pgfmathsubtract{#2}{#1}
+ \pgfmathparse{ abs(#2 - #1)}
+ \pgfmathparse{ abs(#2 - #1)<#3}
+ \ifthenelse{\equal{\pgfmathresult}{1.0}}{#4}{#5}
+}
+
+%\tdplotsetdisplay{\theta_d}{\phi_d}
+%generates the coordinate transformation for defining a TikZ 3d plot display coordinates.
+%#1: user-specified \theta_d, defining the angle through which the system is rotated about the x-axis. 0 points the z-axis "out of the page", while 90 points the z-axis vertically upward on the page.
+%#2: user-specified \phi_d, defining the angle through which the system is rotated about the z-axis. 0 points the x-axis to the right.
+\newcommand{\tdplotsetmaincoords}[2]{%
+%perform some trig for the display transformation
+%
+%
+%store the user-specified angles for possible future use
+\pgfmathsetmacro{\tdplotmaintheta}{#1}
+\pgfmathsetmacro{\tdplotmainphi}{#2}
+%
+%TODO: choose less obvious macro names? or look into scoping?
+\tdplotsinandcos{\sintheta}{\costheta}{\tdplotmaintheta}%
+\tdplotsinandcos{\sinphi}{\cosphi}{\tdplotmainphi}%
+%
+\tdplotmult{\stsp}{\sintheta}{\sinphi}%
+\tdplotmult{\stcp}{\sintheta}{\cosphi}%
+\tdplotmult{\ctsp}{\costheta}{\sinphi}%
+\tdplotmult{\ctcp}{\costheta}{\cosphi}%
+%
+%determine rotation matrix elements for display transformation
+\pgfmathsetmacro{\raarot}{\cosphi}%
+\pgfmathsetmacro{\rabrot}{\sinphi}%
+%NOTE: \rac is zero for this rotation, where z^c always points vertical on the page
+\pgfmathsetmacro{\racrot}{0}%
+\pgfmathsetmacro{\rbarot}{-\ctsp}%
+\pgfmathsetmacro{\rbbrot}{\ctcp}%
+\pgfmathsetmacro{\rbcrot}{\sintheta}%
+%NOTE: third row of rotation matrix not needed for display since screen z is always flat on the page. It is, however, needed when performing further transformations using the Euler transformation.
+\pgfmathsetmacro{\rcarot}{\stsp}%
+\pgfmathsetmacro{\rcbrot}{-\stcp}%
+\pgfmathsetmacro{\rccrot}{\costheta}%
+%
+%now here is where the output is performed
+\tikzset{tdplot_main_coords/.style={x={(\raarot cm,\rbarot cm)},y={(\rabrot cm, \rbbrot cm)},z={(\racrot cm, \rbcrot cm)}}}%
+}
+
+
+%\tdplotsetrotatedcoords{\alpha}{\beta}{\gamma}
+%generates the coordinate transformation for the rotated coordinate system within the display coordinate system. This should be called only after the display coordinate system has been defined. If the display coordinate system changes, this will have to be updated.
+%#1: user-specified euler angle \alpha.
+%#2: user-specified euler angle \beta.
+%#3: user-specified euler angle \gamma.
+\newcommand{\tdplotsetrotatedcoords}[3]{%
+%
+\pgfmathsetmacro{\alphaeul}{#1}
+\pgfmathsetmacro{\betaeul}{#2}
+\pgfmathsetmacro{\gammaeul}{#3}
+%
+%perform some trig for the Euler transformation
+\tdplotsinandcos{\sinalpha}{\cosalpha}{\alphaeul}
+\tdplotsinandcos{\sinbeta}{\cosbeta}{\betaeul}
+\tdplotsinandcos{\singamma}{\cosgamma}{\gammaeul}
+%
+\tdplotmult{\sasb}{\sinalpha}{\sinbeta}
+\tdplotmult{\sbsg}{\sinbeta}{\singamma}
+\tdplotmult{\sasg}{\sinalpha}{\singamma}
+\tdplotmult{\sasbsg}{\sasb}{\singamma}
+%
+\tdplotmult{\sacb}{\sinalpha}{\cosbeta}
+\tdplotmult{\sacg}{\sinalpha}{\cosgamma}
+\tdplotmult{\sbcg}{\sinbeta}{\cosgamma}
+\tdplotmult{\sacbsg}{\sacb}{\singamma}
+\tdplotmult{\sacbcg}{\sacb}{\cosgamma}
+%
+\tdplotmult{\casb}{\cosalpha}{\sinbeta}
+\tdplotmult{\cacb}{\cosalpha}{\cosbeta}
+\tdplotmult{\cacg}{\cosalpha}{\cosgamma}
+\tdplotmult{\casg}{\cosalpha}{\singamma}
+%
+\tdplotmult{\cacbsg}{\cacb}{\singamma}
+\tdplotmult{\cacbcg}{\cacb}{\cosgamma}
+%
+%determine rotation matrix elements for Euler transformation
+\pgfmathsetmacro{\raaeul}{\cacbcg - \sasg}
+\pgfmathsetmacro{\rabeul}{-\cacbsg - \sacg}
+\pgfmathsetmacro{\raceul}{\casb}
+\pgfmathsetmacro{\rbaeul}{\sacbcg + \casg}
+\pgfmathsetmacro{\rbbeul}{-\sacbsg + \cacg}
+\pgfmathsetmacro{\rbceul}{\sasb}
+\pgfmathsetmacro{\rcaeul}{-\sbcg}
+\pgfmathsetmacro{\rcbeul}{\sbsg}
+\pgfmathsetmacro{\rcceul}{\cosbeta}
+%
+%DEBUG: display euler matrix elements
+%\raaeul\ \rabeul\ \raceul
+%
+%\rbaeul\ \rbbeul\ \rbceul
+%
+%\rcaeul\ \rcbeul\ \rcceul
+%
+%now, determine master rotation matrix to define euler-rotated coordinates within the display coordinate frame
+\tdplotmult{\raaeaa}{\raarot}{\raaeul}
+\tdplotmult{\rabeba}{\rabrot}{\rbaeul}
+\tdplotmult{\raceca}{\racrot}{\rcaeul}
+%
+\tdplotmult{\raaeab}{\raarot}{\rabeul}
+\tdplotmult{\rabebb}{\rabrot}{\rbbeul}
+\tdplotmult{\racecb}{\racrot}{\rcbeul}
+%
+\tdplotmult{\raaeac}{\raarot}{\raceul}
+\tdplotmult{\rabebc}{\rabrot}{\rbceul}
+\tdplotmult{\racecc}{\racrot}{\rcceul}
+%
+\tdplotmult{\rbaeaa}{\rbarot}{\raaeul}
+\tdplotmult{\rbbeba}{\rbbrot}{\rbaeul}
+\tdplotmult{\rbceca}{\rbcrot}{\rcaeul}
+%
+\tdplotmult{\rbaeab}{\rbarot}{\rabeul}
+\tdplotmult{\rbbebb}{\rbbrot}{\rbbeul}
+\tdplotmult{\rbcecb}{\rbcrot}{\rcbeul}
+%
+\tdplotmult{\rbaeac}{\rbarot}{\raceul}
+\tdplotmult{\rbbebc}{\rbbrot}{\rbceul}
+\tdplotmult{\rbcecc}{\rbcrot}{\rcceul}
+%
+%the third row is not needed for screen display
+%\tdplotmult{\rcaeaa}{\rcarot}{\raaeul}
+%\tdplotmult{\rcbeba}{\rcbrot}{\rbaeul}
+%\tdplotmult{\rcceca}{\rccrot}{\rcaeul}
+%
+%\tdplotmult{\rcaeab}{\rcarot}{\rabeul}
+%\tdplotmult{\rcbebb}{\rcbrot}{\rbbeul}
+%\tdplotmult{\rccecb}{\rccrot}{\rcbeul}
+%
+%\tdplotmult{\rcaeac}{\rcarot}{\raceul}
+%\tdplotmult{\rcbebc}{\rcbrot}{\rbceul}
+%\tdplotmult{\rccecc}{\rccrot}{\rcceul}
+%
+%set up the master rotation matrix elements
+\pgfmathsetmacro{\raarc}{\raaeaa + \rabeba + \raceca}
+\pgfmathsetmacro{\rabrc}{\raaeab + \rabebb + \racecb}
+\pgfmathsetmacro{\racrc}{\raaeac + \rabebc + \racecc}
+\pgfmathsetmacro{\rbarc}{\rbaeaa + \rbbeba + \rbceca}
+\pgfmathsetmacro{\rbbrc}{\rbaeab + \rbbebb + \rbcecb}
+\pgfmathsetmacro{\rbcrc}{\rbaeac + \rbbebc + \rbcecc}
+%the third row is not needed for screen display
+%\pgfmathsetmacro{\rcarc}{\rcaeaa + \rcbeba + \rcceca}
+%\pgfmathsetmacro{\rcbrc}{\rcaeab + \rcbebb + \rccecb}
+%\pgfmathsetmacro{\rccrc}{\rcaeac + \rcbebc + \rccecc}
+%
+%DEBUG: display master matrix elements
+%\raarc\ \rabrc\ \racrc
+%
+%\rbarc\ \rbbrc\ \rbcrc
+%
+%\rcarc\ \rcbrc\ \rccrc
+%
+\tikzset{tdplot_rotated_coords/.append style={x={(\raarc cm,\rbarc cm)},y={(\rabrc cm, \rbbrc cm)},z={(\racrc cm, \rbcrc cm)}}}%
+}
+
+%\tdplotsetrotatedcoordsorigin{point}
+%this translates the rotated coordinate system to the specified point.
+%#1: user-specified coordinate
+\newcommand{\tdplotsetrotatedcoordsorigin}[1]{%
+%\pgfmathsetmacro{\tdplotrotatedcoordsorigin}{#1}%
+\tikzset{tdplot_rotated_coords/.append style={shift=#1}}%
+}
+
+%\tdplotresetrotatedcoordsorigin
+%this resets the rotated coordinate system translation back to the origin of the main coordinate system
+\newcommand{\tdplotresetrotatedcoordsorigin}{%
+%\pgfmathsetmacro{\tdplotrotatedcoordsorigin}{#1}%
+\tikzset{tdplot_rotated_coords/.append style={shift={(0,0,0)}}}%
+}
+
+%\tdplotsetthetaplanecoords{\phi}
+%this places the rotated coordinate system such that it's x'-y' plane coincides with a "theta plane" for the main coordinate system: This plane contains the z axis, and lies at angle \phi from the x axis.
+%#1: user-specified \phi angle from x-axis
+\newcommand{\tdplotsetthetaplanecoords}[1]{%
+%
+ \tdplotresetrotatedcoordsorigin
+ \tdplotsetrotatedcoords{270 + #1}{270}{0}%
+}
+%note: the following rotation permutes the x, y, and z axes in forward progression. Any value of \alpha greater than 270 will rotate the axes further, allowing for easy selection of the ``theta plane''.
+%\tdplotsetrotatedcoords{270}{270}{00}
+
+%note: the following rotation permutes the x,y, and z axes in backward progression.
+%\tdplotsetrotatedcoords{0}{90}{90}
+
+%\tdplotsetrotatedthetaplanecoords{\phi'}
+%this places the rotated coordinate system into the "theta plane" for the current rotated coordinate system, at user-specified angle \phi'. Note that it replaces the current rotated coordinate system
+%#1: user-specified \phi' angle from x'-axis
+\newcommand{\tdplotsetrotatedthetaplanecoords}[1]{%
+ \tdplotsetrotatedcoords{\alphaeul}{\betaeul}{\gammaeul + #1}%
+ %
+ %permute the coordinates
+ \tikzset{tdplot_rotated_coords/.append style={y={(\raarc cm,\rbarc cm)},z={(\rabrc cm, \rbbrc cm)},x={(\racrc cm, \rbcrc cm)}}}%
+}
+
+%\tdplotsetcoord{point}{r}{theta}{phi}
+%sets a 3d point using spherical polar coordinates. This also generates xy, xz, and yz projections of this point using appropriately named points
+%#1: name of point to set
+%#2: user-specified r coordinate
+%#3: user-specified \theta coordinate
+%#4: user-specified \phi coordinate
+\newcommand{\tdplotsetcoord}[4]{%
+%
+%do some trig to determine angular part of coordinate
+\tdplotsinandcos{\sinthetavec}{\costhetavec}{#3}%
+\tdplotsinandcos{\sinphivec}{\cosphivec}{#4}%
+\tdplotmult{\stcpv}{\sinthetavec}{\cosphivec}%
+\tdplotmult{\stspv}{\sinthetavec}{\sinphivec}%
+%
+%assign the point
+\coordinate (#1) at ($#2*(\stcpv,\stspv,\costhetavec)$);
+%assign the xy, xz, and yz projections of the point
+\coordinate (#1xy) at ($#2*(\stcpv,\stspv,0)$);
+\coordinate (#1xz) at ($#2*(\stcpv,0,\costhetavec)$);
+\coordinate (#1yz) at ($#2*(0,\stspv,\costhetavec)$);
+%assign the x, y, and z projections of the point
+\coordinate (#1x) at ($#2*(\stcpv,0,0)$);
+\coordinate (#1y) at ($#2*(0,\stspv,0)$);
+\coordinate (#1z) at ($#2*(0,0,\costhetavec)$);
+}
+
+\newcommand{\tdplotsimplesetcoord}[4]{%
+%
+%do some trig to determine angular part of coordinate
+\tdplotsinandcos{\sinthetavec}{\costhetavec}{#3}%
+\tdplotsinandcos{\sinphivec}{\cosphivec}{#4}%
+\tdplotmult{\stcpv}{\sinthetavec}{\cosphivec}%
+\tdplotmult{\stspv}{\sinthetavec}{\sinphivec}%
+%
+%assign the point
+\coordinate (#1) at ($#2*(\stcpv,\stspv,\costhetavec)$);
+}
+
+
+%\tdplotdrawarc[coordinate system, draw styles]{center}{r}{angle start}{angle end}{label options}{label}
+%draws an arc and puts a label in the center with specified node options
+%#1: Optional, specifies the coordinate system and any draw style
+%#2: center point of arc
+%#3: radius of arc
+%#4: start angle
+%#5: end angle
+%#6: label options
+%#7: label
+% \tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
+\newcommand{\tdplotdrawarc}[7][tdplot_main_coords]{%
+\pgfmathsetmacro{\tdplottemp}{#5 + #4}
+\tdplotdiv{\tdplottemp}{\tdplottemp}{2}
+\draw[#1] #2 + (\tdplottemp:#3) node[#6]{#7};
+\draw[#1] #2 + (#4:#3) arc (#4:#5:#3);
+}
+
+% \tdplotsphericalsurfaceplot[fill mode]{theta step size}{phi step size}{r}
+%draws a surface in spherical polar coordinates given by r(\theta,\phi), where angular ranges and steps are defined.
+%#1: draw styles
+%#2: theta segments
+%#3: phi segments
+%#4: r(\tdplottheta,\tdplotphi)
+%#5: stroke color
+%#6: fill color
+%#7: x axis instructions, to be rendered when \phi = 0
+%#8: y axis instructions, to be rendered when \phi = 90
+%#9: z axis instructions, to be rendered when plotting is half done
+%TODO: fix axes drawing function when the main display axis phi is at 0, 90, etc.
+\newcommand{\tdplotsphericalsurfaceplot}[9][literal]{%
+%
+ \typeout{3dplot: processing 3d surface plot...}
+
+ %retrieve the angular step sizes
+ \pgfmathsetmacro{\origviewthetastep}{360/#2}
+ \pgfmathsetmacro{\origviewphistep}{360/#3}
+
+ %determing the angular starting point, based on the step size and display orientation
+ \pgfmathparse{ mod(90 + \tdplotmainphi,\origviewphistep)}
+ \pgfmathsetmacro{\originalphi}{90 + \tdplotmainphi - \pgfmathresult}
+
+ \pgfmathparse{ mod(\tdplotmaintheta,\origviewthetastep)}
+ \pgfmathsetmacro{\originaltheta}{\tdplotmaintheta - \pgfmathresult}
+
+
+ %this fudge factor helps when properly rendering x and y axes
+ \pgfmathsetmacro{\tdplotsuperfudge}{\originaltheta > 90}
+
+ %draw back part of shape, doing left and right side individually
+ \foreach \leftright in {1,-1}
+ {
+ \pgfmathsetmacro{\viewphistart}{\originalphi}
+ \pgfmathsetmacro{\viewphistep}{\leftright * \origviewphistep}
+ \pgfmathsetmacro{\viewphiinc}{\viewphistart + \viewphistep}
+ \pgfmathsetmacro{\viewphiend}{\viewphistart + \leftright * 90 - \viewphistep}
+
+ \foreach \curphi in{\viewphistart,\viewphiinc,...,\viewphiend}
+ {
+ %draw upper and lower parts individually, starting at the point opposite display angle
+ \foreach \topbottom in {1,-1}
+ {
+ \pgfmathsetmacro{\viewthetastep}{\topbottom * \origviewthetastep}
+ \pgfmathsetmacro{\viewthetastart}{180 - \originaltheta}
+
+ \ifnum \topbottom=1
+ \pgfmathsetmacro{\viewthetaend}{180 - \origviewthetastep}
+ \else
+ \pgfmathsetmacro{\viewthetaend}{\origviewthetastep}
+ \fi
+ \pgfmathsetmacro{\viewthetainc}{\viewthetastart + \viewthetastep}
+
+ %perform the rendering
+ \tdplotdosurfaceplot{#4}{#7}{#8}{#5}{#6}{#1}
+ }
+ }
+ }
+ \begin{scope}[opacity=1]
+ #9 %draw z axis content
+ \end{scope}
+
+ %draw front part of shape, doing left and right sides individually
+ \pgfmathsetmacro{\tdplotsuperfudge}{\originaltheta < 90}
+ \foreach \leftright in {1,-1}
+ {
+ \pgfmathsetmacro{\viewphistep}{\leftright * \origviewphistep}
+ \pgfmathsetmacro{\viewphistart}{\originalphi + \leftright * 90}
+ \pgfmathsetmacro{\viewphiinc}{\viewphistart + \viewphistep}
+ \pgfmathsetmacro{\viewphiend}{\viewphistart + \leftright * 90 - \viewphistep}
+
+ \foreach \curphi in{\viewphistart,\viewphiinc,...,\viewphiend}
+ {
+ %draw upper and lower parts individually, starting at the either the north or south pole
+ \foreach \topbottom in {1,-1}
+ {
+ \pgfmathsetmacro{\viewthetastep}{-\topbottom * \origviewthetastep}
+ \ifnum \topbottom=1
+ \pgfmathsetmacro{\viewthetastart}{180}
+ \else
+ \pgfmathsetmacro{\viewthetastart}{0}
+ \fi
+
+ \pgfmathsetmacro{\viewthetaend}{\originaltheta - \viewthetastep}
+ \pgfmathsetmacro{\viewthetainc}{\viewthetastart + \viewthetastep}
+
+ %perform the rendering
+ \tdplotdosurfaceplot{#4}{#7}{#8}{#5}{#6}{#1}
+ }
+ }
+ }
+}
+
+%sets the angular range of the polar plot to user-specified values
+\newcommand{\tdplotsetpolarplotrange}[4]{%
+ \pgfmathsetmacro{\lowerphi}{#3}
+ \pgfmathsetmacro{\upperphi}{#4}
+ \pgfmathsetmacro{\lowertheta}{#1}
+ \pgfmathsetmacro{\uppertheta}{#2}
+}
+
+\newcommand{\tdplotresetpolarplotrange}{%
+ \pgfmathsetmacro{\lowerphi}{0}
+ \pgfmathsetmacro{\upperphi}{360}
+ \pgfmathsetmacro{\lowertheta}{0}
+ \pgfmathsetmacro{\uppertheta}{180}
+}
+
+
+
+%internal command, performs the actual rendering for the \tdplotsphericalsurfaceplot command
+%TODO: find proper syntax and format for internal commands not intended to be used by the general user
+\newcommand{\tdplotdosurfaceplot}[6]{%
+
+ \pgfmathsetmacro{\nextphi}{\curphi + \tdplotsuperfudge*\viewphistep}
+
+ \begin{scope}[opacity=1]
+ %check if the current phi angle is in position to draw the x axis
+ \tdplotcheckdiff{\nextphi}{360}{\origviewphistep}{#2}{}
+ \tdplotcheckdiff{\nextphi}{0}{\origviewphistep}{#2}{}
+
+ %check if the current phi angle is in position to draw the y axis
+ \tdplotcheckdiff{\nextphi}{90}{\origviewphistep}{#3}{}
+ \tdplotcheckdiff{\nextphi}{450}{\origviewphistep}{#3}{}
+ \end{scope}
+
+ %do the theta sweep
+ \foreach \curtheta in{\viewthetastart,\viewthetainc,...,\viewthetaend}
+ {
+
+ %convert phi, theta coords into longitude, latitude to make use of pgfpointspherical coordinates
+ \pgfmathsetmacro{\curlongitude}{90 - \curphi}
+ \pgfmathsetmacro{\curlatitude}{90 - \curtheta}
+
+ %If sweeping to the right, shift the value of phi to the lower value of phi.
+ \ifthenelse{\equal{\leftright}{-1.0}}%
+ {%
+ \pgfmathsetmacro{\curphi}{\curphi - \origviewphistep}
+ }{}
+ %\fi
+
+ \pgfmathsetmacro{\tdplottheta}{mod(\curtheta,360)}
+ \pgfmathsetmacro{\tdplotphi}{mod(\curphi,360)}
+
+ \pgfmathparse{\tdplotphi < 0}
+ \ifthenelse{\equal{\pgfmathresult}{1.0}}{
+ \pgfmathsetmacro{\tdplotphi}{\tdplotphi + 360}
+ }{}%
+
+ %test to see if this value is within the specified angular range
+ \pgfmathparse{\tdplottheta > \uppertheta}
+ \pgfmathsetmacro{\logictest}{1 - \pgfmathresult}
+
+ \pgfmathparse{\tdplottheta < \lowertheta}
+ \pgfmathsetmacro{\logictest}{\logictest * (1 - \pgfmathresult)}
+
+ \pgfmathsetmacro{\tdplottheta}{\tdplottheta + \viewthetastep}
+ \pgfmathparse{\tdplottheta > \uppertheta}
+ \pgfmathsetmacro{\logictest}{\logictest * (1 - \pgfmathresult)}
+
+ \pgfmathparse{\tdplottheta < \lowertheta}
+ \pgfmathsetmacro{\logictest}{\logictest * (1 - \pgfmathresult)}
+
+ \pgfmathparse{\tdplotphi > \upperphi}
+ \pgfmathsetmacro{\logictest}{\logictest * (1 - \pgfmathresult)}
+
+ \pgfmathparse{\tdplotphi < \lowerphi}
+ \pgfmathsetmacro{\logictest}{\logictest * (1 - \pgfmathresult)}
+
+ \pgfmathsetmacro{\tdplotphi}{\tdplotphi + \viewphistep}
+
+ \pgfmathparse{\tdplotphi < 0}
+ \ifthenelse{\equal{\pgfmathresult}{1.0}}{
+ \pgfmathsetmacro{\tdplotphi}{\tdplotphi + 360}
+ }{}%
+
+ \pgfmathparse{\tdplotphi > \upperphi}
+ \pgfmathsetmacro{\logictest}{\logictest * (1 - \pgfmathresult)}
+
+ \pgfmathparse{\tdplotphi < \lowerphi}
+ \pgfmathsetmacro{\logictest}{\logictest * (1 - \pgfmathresult)}
+
+
+ \pgfmathsetmacro{\tdplottheta}{\curtheta}
+ \pgfmathsetmacro{\tdplotphi}{\curphi}
+
+
+ \ifthenelse{\equal{#6}{parametricfill}}{%
+ \pgfmathsetmacro{\radius}{#1}
+ \pgfmathlessthan{\radius}{0}
+ \pgfmathsetmacro{\phaseshift}{180 * \pgfmathresult}
+
+ \pgfmathsetmacro{\colorarg}{#5}
+ \pgfmathsetmacro{\colorarg}{\colorarg + \phaseshift}
+ \pgfmathsetmacro{\colorarg}{mod(\colorarg,360)}
+
+ \pgfmathlessthan{\colorarg}{0}
+ \pgfmathsetmacro{\colorarg}{\colorarg + 360*\pgfmathresult}
+
+ \pgfmathdivide{\colorarg}{360}
+ \definecolor{tdplotfillcolor}{hsb}{\pgfmathresult, 1, 1}
+ \color{tdplotfillcolor}
+ }%
+ {%
+ \pgfsetfillcolor{#5}
+ }
+ \pgfsetstrokecolor{#4}
+
+ \ifthenelse{\equal{\leftright}{-1.0}}%
+ {%
+ \pgfmathsetmacro{\curphi}{\curphi + \origviewphistep}
+ }{}
+ %\fi
+
+ \ifthenelse{\equal{\logictest}{1.0}}{%
+ \pgfmathsetmacro{\radius}{abs(#1)}
+ \pgfpathmoveto{\pgfpointspherical{\curlongitude}{\curlatitude}{\radius}}
+
+ \pgfmathsetmacro{\tdplotphi}{\curphi + \viewphistep}
+ \pgfmathsetmacro{\radius}{abs(#1)}
+ \pgfpathlineto{\pgfpointspherical{\curlongitude - \viewphistep}{\curlatitude}{\radius}}
+
+ \pgfmathsetmacro{\tdplottheta}{\curtheta + \viewthetastep}
+ \pgfmathsetmacro{\radius}{abs(#1)}
+ \pgfpathlineto{\pgfpointspherical{\curlongitude - \viewphistep}{\curlatitude - \viewthetastep}{\radius}}
+
+ \pgfmathsetmacro{\tdplotphi}{\curphi}
+ \pgfmathsetmacro{\radius}{abs(#1)}
+ \pgfpathlineto{\pgfpointspherical{\curlongitude}{\curlatitude - \viewthetastep}{\radius}}
+ \pgfpathclose
+
+ \pgfusepath{fill,stroke}
+ }{}
+ }
+}
+
+%\tdplotshowargcolorguide{x position}{y position}{x size}{y size}
+%#1: screen x position
+%#2: screen y position
+%#3: x size (susceptible to scale)
+%#4: y size (susceptible to scale)
+\newcommand{\tdplotshowargcolorguide}[4]{
+
+\pgfmathsetmacro{\tdplotx}{#1}
+\pgfmathsetmacro{\tdploty}{#2}
+\pgfmathsetmacro{\tdplothuestep}{5}
+\pgfmathsetmacro{\tdplotxsize}{#3}
+\pgfmathsetmacro{\tdplotysize}{#4}
+
+\pgfmathsetmacro{\tdplotyscale}{\tdplotysize/360}
+
+\foreach \tdplotphi in {0,\tdplothuestep,...,360}
+{
+ \pgfmathdivide{\tdplotphi}{360}
+ \definecolor{tdplotfillcolor}{hsb}{\pgfmathresult, 1, 1}
+ \color{tdplotfillcolor}
+
+ \pgfmathsetmacro{\tdplotstarty}{\tdploty + \tdplotphi * \tdplotyscale}
+ \pgfmathsetmacro{\tdplotstopy}{\tdplotstarty + \tdplothuestep * \tdplotyscale}
+ \pgfmathsetmacro{\tdplotstartx}{\tdplotx}
+ \pgfmathsetmacro{\tdplotstopx}{\tdplotx + \tdplotxsize}
+ \filldraw[tdplot_screen_coords] (\tdplotstartx,\tdplotstarty) rectangle (\tdplotstopx,\tdplotstopy);
+}
+
+ \pgfmathsetmacro{\tdplotstopy}{\tdploty + (360+\tdplothuestep)*\tdplotyscale }
+ \pgfmathsetmacro{\tdplotstopx}{\tdplotx + \tdplotxsize}
+
+\draw[tdplot_screen_coords] (\tdplotx,\tdploty) rectangle (\tdplotstopx,\tdplotstopy);
+
+\node[tdplot_screen_coords,anchor=west,xshift=5pt] at (\tdplotstopx,\tdploty) {$0$};
+\node[tdplot_screen_coords,anchor=west,xshift=5pt] at (\tdplotstopx,\tdplotstopy) {$2\pi$};
+
+ \pgfmathsetmacro{\tdplotstopy}{\tdploty + (360+\tdplothuestep)/2*\tdplotyscale }
+\node[tdplot_screen_coords,anchor=west, xshift=5pt] at (\tdplotstopx, \tdplotstopy) {$\pi$};
+}
+
+
+%Notes
+%-----
+
+%PROBLEM:
+%the line-by-line coordinate transformation does not accept predefined points. It only works with literal points. Example:
+%\begin{tikzpicture}[smooth]
+% \draw plot coordinates{(1,0)(2,0.5)(3,0)(3,1)};
+% \draw[x={(0cm,1cm)},y={(1cm,0cm)},color=red] plot coordinates{(1,0)(2,0.5)(3,0)(3,1)};
+%\end{tikzpicture}
+%
+%\begin{tikzpicture}[smooth]
+% \coordinate (A) at (1,0);
+% \coordinate (B) at (2,0.5);
+% \coordinate (C) at (3,0);
+% \coordinate (D) at (3,1);
+% \draw plot coordinates{(A)(B)(C)(D)};
+% \draw[x={(0cm,1cm)},y={(1cm,0cm)},color=red] plot coordinates{(A)(B)(C)(D)};
+%\end{tikzpicture}
+%SOLUTION: none so far, other than use literal points.
+
+
+%PROBLEM:
+% \node[tdplot_rotated_coords,anchor=south west] at (\thetavec/2:.5){$\theta$};
+%it looks like the \node command can't be placed properly when a shift={} is defined in a style?
+%SOLUTION: Use something like this instead:
+%\draw[tdplot_rotated_coords] (O) + (\thetavec/2:.5) node[anchor=south west]{$\theta$};
+
+
+%PROBLEM:
+ %\draw[-stealth,color=orange] (0,0,0) -- (xyz spherical cs:radius=.5,longitude=60,latitude=120);
+%this gives the compile error: Undefined control sequence. <argument> \tikz@cs@radius. Not sure if this is due to some missing code in the TikZ 3d library.
+%SOLUTION: none found yet.