I want to draw a region in a 3D envirement. At the moment I'm doing this using tikz. The region is defined by the addition of a translation (1) and a rotation (2). The resuling region in 2D would be described in (3)
My first attemt was to draw a ball for the translation (as in (1)) and then move the ball along the rotation-line (as in (2)) to get the hole region (as in (3)).
My problem with this solution is:
- It takes to long to open the resuling pdf
- The shading of the resulting picture is too plain, you can't realy see the form.
Here is the code for the 3D envirement with the rotation around yaw and pitch (still missing roll). The resulting figures you can see in (4) and (5), this is the same object with different rotations. Because there is a lot of other stuff around, I marked the main part with "% THIS IS THE MAIN PART !!!!" and the end with "% END OF MAIN PART !!!!".
\newcommand{\rotateRPY}[4][0/0/0]% point to be saved to \savedxyz, roll, pitch, yaw
{
\pgfmathsetmacro{\rollangle}{#2}
\pgfmathsetmacro{\pitchangle}{#3}
\pgfmathsetmacro{\yawangle}{#4}
% to what vector is the x unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newxx}{cos(\yawangle)*cos(\pitchangle)}% a
\pgfmathsetmacro{\newxy}{sin(\yawangle)*cos(\pitchangle)}% d
\pgfmathsetmacro{\newxz}{-sin(\pitchangle)}% g
\path (\newxx,\newxy,\newxz);
\pgfgetlastxy{\nxx}{\nxy};
% to what vector is the y unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newyx}{cos(\yawangle)*sin(\pitchangle)*sin(\rollangle)-sin(\yawangle)*cos(\rollangle)}% b
\pgfmathsetmacro{\newyy}{sin(\yawangle)*sin(\pitchangle)*sin(\rollangle)+ cos(\yawangle)*cos(\rollangle)}% e
\pgfmathsetmacro{\newyz}{cos(\pitchangle)*sin(\rollangle)}% h
\path (\newyx,\newyy,\newyz);
\pgfgetlastxy{\nyx}{\nyy};
% to what vector is the z unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newzx}{cos(\yawangle)*sin(\pitchangle)*cos(\rollangle)+ sin(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzy}{sin(\yawangle)*sin(\pitchangle)*cos(\rollangle)-cos(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzz}{cos(\pitchangle)*cos(\rollangle)}
\path (\newzx,\newzy,\newzz);
\pgfgetlastxy{\nzx}{\nzy};
% transform the point given by #1
\foreach \x/\y/\z in {#1}
{
\pgfmathsetmacro{\transformedx}{\x*\newxx+\y*\newyx+\z*\newzx}
\pgfmathsetmacro{\transformedy}{\x*\newxy+\y*\newyy+\z*\newzy}
\pgfmathsetmacro{\transformedz}{\x*\newxz+\y*\newyz+\z*\newzz}
\xdef\savedx{\transformedx}
\xdef\savedy{\transformedy}
\xdef\savedz{\transformedz}
}
}
\tikzset{RPY/.style={x={(\nxx,\nxy)},y={(\nyx,\nyy)},z={(\nzx,\nzy)}}}
%start tikz picture, and use the tdplot_main_coords style to implement the display
%coordinate transformation provided by 3dplot
\begin{tikzpicture}[scale=1,tdplot_main_coords]
% \begin{tikzpicture}[tdplot_main_coords]
%define polar coordinates for some vector
%TODO: look into using 3d spherical coordinate system
% \pgfmathsetmacro{\rvec}{0.8}
% \pgfmathsetmacro{\thetavec}{90}
% \pgfmathsetmacro{\phivec}{60}
\pgfmathsetmacro{\Xoffset}{0.6}
\pgfmathsetmacro{\Yoffset}{0.7}
\pgfmathsetmacro{\Zoffset}{0}
\draw[white,very thin] (2,0,0) circle (4.5cm); %just for all figure to have the same size
%set up some coordinates
%-----------------------
\coordinate (O) at (0,0,0);
%determine a coordinate (P) using (r,\theta,\phi) coordinates. This command
%also determines (Pxy), (Pxz), and (Pyz): the xy-, xz-, and yz-projections
%of the point (P).
%syntax: \tdplotsetcoord{Coordinate name without parentheses}{r}{\theta}{\phi}
% \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\coordinate (P) at (\Xoffset,\Yoffset,\Zoffset);
%draw figure contents
\newcommand\errTrans{ 1 }
\newcommand\errRot{ 30 }
\newcommand\pointX{ 5 }
\newcommand\pointY{ 0 }
\newcommand\pointZ{ 0 }
\newcommand\pointDist{ sqrt( \pointX * \pointX + \pointY * \pointY + \pointZ * \pointZ ) }
\coordinate (point) at (\pointX, \pointY, \pointZ);
\newcommand\pointDistPlus{ sqrt( (\pointX + \errTrans) * (\pointX + \errTrans) + \pointY * \pointY + \pointZ * \pointZ ) }
\newcommand\pointDistMinus{ sqrt( (\pointX - \errTrans) * (\pointX - \errTrans) + \pointY * \pointY + \pointZ * \pointZ ) }
\coordinate (point) at (\pointX, \pointY, \pointZ);
% THIS IS THE MAIN PART !!!!
% THIS IS THE MAIN PART !!!!
% THIS IS THE MAIN PART !!!!
% THIS IS THE MAIN PART !!!!
\foreach \pitch in {-\errRot,...,\errRot}
{
\foreach \yaw in {-\errRot,...,\errRot}
{
\coordinate (ptOffset) at ( { ( (cos(\yaw ) - 1) + cos(abs(\pitch))) * \pointDist },
{ sin(\yaw ) * \pointDist },
{ sin(\pitch) * \pointDist }
);
\coordinate (pt) at ($(O) + (ptOffset)$);
\shade [ball color=blue] (pt) circle [radius=1cm];
}
}
% END OF MAIN PART !!!!
% END OF MAIN PART !!!!
% END OF MAIN PART !!!!
% END OF MAIN PART !!!!
%draw the main coordinate system axes
\draw[red,very thick,->] (0,0,0) -- (1, 0, 0) node[anchor=north east]{$x$};
\draw[green,very thick,->] (0,0,0) -- (0, 1, 0) node[anchor=north west]{$y$};
\draw[blue,very thick,->] (0,0,0) -- (0, 0, 1) node[anchor=south]{$z$};
\shade [ball color=red] (point) circle [radius=0.1cm];
\end{tikzpicture}
Does anybody has an idea how to draw this, 1. in a better way at all and 2. with a shading where it actualy is possible to see anything?