# 圓柱形狀圖元的UV偏導數

pbrt-3中，cylinder.cpp的相關部分為：（i）與上述紫外線相同；（ii）$$\ partial \ mathbf {p} / \ partial u$$但是不同：

Float u = phi / phiMax;
Float v = (pHit.z - zMin) / (zMax - zMin);

// Compute cylinder $$\dpdu$$ and $$\dpdv$$
Vector3f dpdu(-phiMax * pHit.y, phiMax * pHit.x, 0);
Vector3f dpdv(0, 0, zMax - zMin);


I think it's easiest to get the tangent frame by writing the forward mapping from $$(u,v)$$ to $$\mathbf{p}$$: $$\mathbf{p}(u,v) = \begin{bmatrix} R \, \cos (2\pi u) \\ R \, \sin (2\pi u) \\ vL \end{bmatrix}$$ Then you can see that the derivatives are: $$\frac{\partial\mathbf{p}}{\partial u} = \begin{bmatrix} -2\pi R \, \sin(2\pi u) \\ 2\pi R \, \cos(2\pi u) \\ 0\end{bmatrix} = \begin{bmatrix} -2\pi y \\ 2\pi x \\ 0\end{bmatrix}, \qquad \frac{\partial\mathbf{p}}{\partial v} = \begin{bmatrix} 0 \\ 0 \\ L \end{bmatrix}$$ which matches the pbrt code.

I think your derivation went wrong by assuming that $$\partial\mathbf{p}/\partial u$$ was the component-wise reciprocal of $$\partial u / \partial{\mathbf{p}}$$. It's not so simple, because the latter object is really the gradient of $$u$$, where $$u$$ is now considered as a scalar field defined over all space (not just on the cylinder). To invert this properly we really need another coordinate running perpendicular to $$u$$ in the $$xy$$ plane, so that we have a locally invertible mapping; then we can take its Jacobian matrix and invert that. We can use the radius $$R$$ as such a coordinate. Then we have the inverse mapping, \begin{aligned} u(x,y) &= \frac{1}{2\pi} \arctan(y,x) \\ R(x,y) &= \sqrt{x^2 + y^2} \end{aligned} whose Jacobian is: $$\frac{\partial(u,R)}{\partial(x,y)} = \begin{bmatrix} \tfrac{\partial u}{\partial x} & \tfrac{\partial u}{\partial y} \\ \tfrac{\partial R}{\partial x} & \tfrac{\partial R}{\partial y} \end{bmatrix} = \begin{bmatrix} -y/(2\pi R^2) & x/(2\pi R^2) \\ x/R & y/R \end{bmatrix}$$ and the inverse of that is: $$\frac{\partial(x,y)}{\partial(u,R)} = -2\pi R \begin{bmatrix} y/R & -x/(2\pi R^2) \\ -x/R & -y/(2\pi R^2) \end{bmatrix} = \begin{bmatrix} -2\pi y & x/R \\ 2\pi x & y/R \end{bmatrix}$$ from which you can then read off $$\partial{(x,y)}/\partial u$$ as the first column, which matches the result obtained for $$\partial\mathbf{p}/\partial u$$ above.