It looks like what you're doing is reversing the order of rotations. Is that correct? I think of rotations in terms of matrix multiplication. If you have a 3-dimensional vector,
$\displaystyle \vec{r}=\left[\begin{matrix}x\\ y\\ z\end{matrix}\right],$
you can rotate it about the x-axis through an angle $\displaystyle \theta$ by left-multiplying by a rotation matrix to obtain the rotated vector $\displaystyle \vec{r}_{\text{rot}}$ thus:
$\displaystyle \vec{r}_{\text{rot}}=
\left[\begin{matrix}
1 &0 &0\\
0 &\cos(\theta) &-\sin(\theta)\\
0 &\sin(\theta) &\cos(\theta)\end{matrix}\right]\left[\begin{matrix}x\\ y\\ z\end{matrix}\right].$
The other rotations you can see here.
Now, in your case, it looks like in the pan tilt case, you're applying a z rotation followed by an x or y rotation (depending on your orientation). In the tilt bank case, it's a little hard to see exactly what you're doing. The picture is a bit hard to decipher. Your pan tilt is like this, correct? Can you possibly draw a clearer picture of the tilt bank case?
Thanks Ackbeet,
I was wondering if this one was going to get answered.
Attached is a better picture of what I am trying to transform. On the left is the normal pan and tilt similar to the pan tilt camera you linked. The top red tilt axis is rotated about the vertical pan axis (blue). The red axis rotates atop the blue axis in the direction indicated. On the right, the red tilt axis is rotated in the direction indicated and the yellow bank axis is attached to the red tilt axis so that it is rotated with it. The bank axis then rotates about it's own axis. This is actually already built and I am attempting to do the transform to track the sun given pan and tilt degrees.
I knew the transform involved doing a matrix but 20 years of not using it has left me in the lurch on this one.
The solar panel sits atop the bank axis and a combination of the tilt and bank axes will allow the tracker to follow the sun via the NREL software. Any help is appreciated. I'm trying to get this into a formula form so I can feed pan and tilt into it and dump out tilt and bank degrees.
Thanks again,
T
Thanks for the second picture. It's definitely clearer than the first.
Let's assign some variables to things. In the pan/tilt picture, let the $\displaystyle \hat{i}$ axis be along the red rod, oriented positively from left to right. Let the $\displaystyle \hat{j}$ axis be along the blue rod, oriented positively up. By the right-hand rule, then, we must have the $\displaystyle \hat{k}$ axis be coming out of the picture towards us, and orthogonal to both the previous axes. Let us suppose you have a camera mounted on the red rod. I'm going to assume that, if the pan is at $\displaystyle 0$ radians, and the tilt is also at $\displaystyle 0$ radians, then the camera would then be pointed straight up, in the $\displaystyle +\hat{j}$ direction. Is all this clear?
In the tilt/bank picture, we will utilize the same coordinate system. That is, the $\displaystyle \hat{i}$ axis is along the red rod, oriented positively from left to right. The $\displaystyle \hat{j}$ axis is vertical (where the yellow rod would be if it were vertical), and positive up. And the $\displaystyle \hat{k}$ axis is coming out of the picture. In this picture, we would need to have the camera mounted on the yellow rod so that if the tilt were at $\displaystyle 0$ radians, and the bank were at $\displaystyle 0$ radians, the camera would be pointed in the positive $\displaystyle \hat{i}$ direction. Is that clear?
The problem then becomes: given an $\displaystyle \alpha$ pan rotation followed by a $\displaystyle \beta$ tilt rotation, all applied to the unit $\displaystyle \hat{j}$ vector, resulting in the arbitrary unit vector $\displaystyle \hat{r}$: produce the same vector by applying first a $\displaystyle \gamma$ tilt rotation, followed by a $\displaystyle \delta$ bank rotation, all applied to the unit $\displaystyle \hat{i}$ vector. Is this correct?
Hi Ackbeet,
Yup, I'm with you.Let's assign some variables to things. In the pan/tilt picture, let the axis be along the red rod, oriented positively from left to right. Let the axis be along the blue rod, oriented positively up. By the right-hand rule, then, we must have the axis be coming out of the picture towards us, and orthogonal to both the previous axes. Let us suppose you have a camera mounted on the red rod. I'm going to assume that, if the pan is at radians, and the tilt is also at radians, then the camera would then be pointed straight up, in the direction. Is all this clear?
Think so, but I'm not sure that is where I am going with this. The solar panel is attached to the cylindical part of the yellow rod. Normally facing +/-45° from positive with the yellow rod in the orientation displayed. There are mechanical limits on the system that prevent the bank axis from rotating past 45°. With the orientation as you are describing, there are infinite solutions to the tilt equation when the panel faces positive . Maybe I am getting ahead of myself though.In the tilt/bank picture, we will utilize the same coordinate system. That is, the axis is along the red rod, oriented positively from left to right. The axis is vertical (where the yellow rod would be if it were vertical), and positive up. And the axis is coming out of the picture. In this picture, we would need to have the camera mounted on the yellow rod so that if the tilt were at radians, and the bank were at radians, the camera would be pointed in the positive direction. Is that clear?
I'm not sure I understand the application to the unit vector. This is due the the first rotating body being on that axis? My gut says this is a correct description of the problem but my head is still having trouble wrapping around it. In the end the panel or camera should be facing the same direction for both systems as long as it it within the mechanical limits. The formula is the same either way.The problem then becomes: given an pan rotation followed by a tilt rotation, all applied to the unit vector, resulting in the arbitrary unit vector : produce the same vector by applying first a tilt rotation, followed by a bank rotation, all applied to the unit vector. Is this correct?
It is amazing how much one can forget. It's like I'm learning it all over again.
Thank you for the assistance, I'd love to borrow your brain for a couple of days.
T.
Ah. Your last post explains why I didn't launch into any computations yet. I was expecting there to be some mechanical limitations on your system. When we finally get an equation that does what you want, you're going to have to put in checks on the results to make sure they are in the feasible region.
I don't suppose you could draw the default position of your solar panel into the picture, could you? Or maybe, you could give a vector triple: $\displaystyle \langle x,y,z\rangle$ that describes the initial orientation of the panel? Here's my guess at what you meant: with the yellow rod pointed in the $\displaystyle -\hat{k}$ direction, a vector normal to the working plane of the solar panel would point in the $\displaystyle \frac{\langle 0,1,-1\rangle}{\sqrt{2}}$ direction. Is that correct?
Hi again,
See the attached modified pic. I hope that clears it all up. I knew going in that the mechanical limitations would not allow a sun up to sun down track of the sun and have already coded the program to stop the tracking process when the limits are reached. The sun in my location at the summer solstice on the pan and tilt pans over 180 degress. I never would have thought that but it is true.
The panel mounted to the round side of the bank axis has it's normal in facing straight up in the picture.
Thanks again,
T
I've got the answer, and I'm pretty sure it's correct. I'll post the punch-line now, and give the justification later, when I have time to type it up (it's a bit long). This has been a very fun problem. Thanks for posting it!
In the pan/tilt case, if the pan angle is $\displaystyle \alpha$, and the tilt angle is $\displaystyle \beta$, and if in the tilt/bank case the tilt angle is $\displaystyle \gamma$ and the bank angle is $\displaystyle \delta$, then the following equations hold:
$\displaystyle \sin(\delta)=\sin(\alpha)\sin(\beta),$ and
$\displaystyle \cos(\gamma)=\frac{\cos(\beta)}{\sqrt{1-\sin^{2}(\alpha)\sin^{2}(\beta)}}.$
Try that on for size. As I said above, I'll post the justification when I have the time.
Hey Ackbeet,
This was much more elegant than I had imagined it would be. I'm going to test it over the next couple of days and see how it does. I'll let you know. You are the man. Next time I have a completely baffling problem, I know who to call.
Thank you for all of your hard work.
T
Ok, here goes:
According to the wiki on matrix rotations in 3D, the following matrix rotates the positive $\displaystyle \hat{j}$ through an angle $\displaystyle \theta=\pi/2$ to the positive $\displaystyle \hat{k}$:
$\displaystyle R_{x}(\theta)=\left[\begin{matrix}1 & 0 & 0 \cr 0 & \cos (x) & -\sin (x) \cr 0 & \sin (x) & \cos (x) \cr\end{matrix}\right].$
You can check that this works. Also, the following matrix rotates the positive $\displaystyle \hat{k}$ through an angle $\displaystyle \theta=\pi/2$ to the positive $\displaystyle \hat{i}$:
$\displaystyle R_{y}(\theta)=\left[\begin{matrix}\cos (x) & 0 & \sin (x) \cr 0 & 1 & 0 \cr -\sin (x) & 0 & \cos (x) \cr\end{matrix}\right].$
Finally, the following matrix rotates the positive $\displaystyle \hat{i}$ through an angle $\displaystyle \theta=\pi/2$ to the positive $\displaystyle \hat{j}$:
$\displaystyle R_{z}(\theta)=\left[\begin{matrix}\cos (x) & -\sin (x) & 0 \cr \sin (x) & \cos (x) & 0 \cr 0 & 0 & 1 \cr\end{matrix}\right].$
In comparing these rotations to the rotations in your latest picture, it is evident that in the pan/tilt case, you have the following two rotations: $\displaystyle R_{x}(-\beta)$ and $\displaystyle R_{y}(\alpha).$ Similarly, in the tilt/bank case, you have the following rotations: $\displaystyle R_{z}(\delta)$ and $\displaystyle R_{x}(-\gamma).$
Query: is the pan/tilt case giving us $\displaystyle R_{x}(-\beta)R_{y}(\alpha)\hat{j},$ or $\displaystyle R_{y}(\alpha)R_{x}(-\beta)\hat{j}?$ It is not self-evident which one is correct. Note that these two are not the same, since matrix multiplication is not commutative. However, by plugging in a simple base case of $\displaystyle \alpha=\pi/2$ and $\displaystyle \beta=\pi/2$, you can check that the correct order is $\displaystyle R_{y}(\alpha)R_{x}(-\beta)\hat{j}.$ Similarly, for the tilt/bank case, the correct order is $\displaystyle R_{x}(-\gamma)R_{z}(\delta)\hat{j}.$ We now simply set
$\displaystyle R_{y}(\alpha)R_{x}(-\beta)\hat{j}=R_{x}(-\gamma)R_{z}(\delta)\hat{j}.$
This gives us the following system of simultaneous equations:
$\displaystyle \left[\begin{matrix}
-\sin(\alpha)\sin(\beta)\\ \cos(\beta)\\ -\cos(\alpha)\sin(\beta)
\end{matrix}\right]=\left[\begin{matrix}
-\sin(\delta)\\ \cos(\gamma)\cos(\delta)\\ -\cos(\delta)\sin(\gamma)
\end{matrix}\right].$
The solution I gave in post #10 satisfies all three of these equations.
So there's my solution, leaving out a few steps in the middle here and there.
You're very welcome for this solution. I enjoyed it!
Have a good one.
One further note: for computational efficiency, you might consider coding up this transformation as follows:
$\displaystyle \sin(\delta)=\sin(\alpha)\sin(\beta),$ and
$\displaystyle \cos(\gamma)=\frac{\cos(\beta)}{\sqrt{1-\sin^{2}(\delta)}}=\frac{\cos(\beta)}{\cos(\delta) }.$
The idea here is, you use the first equation to compute $\displaystyle \delta$, and then you have what you need to compute $\displaystyle \gamma$ from the second equation.
Ok, I ran some test data though excel with columns added for the above calculations.
I'm checking to make sure I didn't botch the transfer into Excel.
Here is the tilt calculation:
=DEGREES(ASIN(SIN(RADIANS(D2))*SIN(RADIANS(F2))))
Where D column contains the Pan Degrees and F column contains the tilt degrees.
Here is the bank calculation:
=DEGREES(ACOS(COS(RADIANS(F2))/COS(RADIANS(L2))))
Where F column contains the tilt degrees and L column contains the result of the tilt calculation.
In hindsight, I probably should have given you a data set to work with.
If I run a column of tilt data at a constant 21 degree tilt and a column of pan information from 0 to 180 I get a nice smooth translation with 90° being solar zenith. Next I'll go to MIDC: Solar Position Algorithm (SPA) Calculator for some real data to run through it.
Thanks again,
T