问题描述
我想围绕 0° 方向轴对以下 2D 极坐标图执行 360° 旋转:
我没有描述它的分析函数(例如 f = R(theta)),但只有两个离散数组:半径值和角度 theta
令 R 为包含极坐标图半径值的向量:
xv = R.* cos(theta); % // Polar to 2D Cartesian coordinates
yv = R.* sin(theta); % // Polar to 2D Cartesian coordinates
phi = 0:.001:2*pi; % // 3D revolution angle around theta = 0
% // 3D points of the surface
xf = repmat(xv',size(phi));
yf = yv' * cos(phi);
zf = yv' * sin(phi);
mesh(xf,yf,zf)
上面的代码绘制了这个:
看起来是正确的,但是:
- zf 值(请参阅颜色条)的范围与我对极坐标图的简单 360° 旋转所期望的范围不同。这是因为 zf 是坐标变换的结果。
- 颜色图算法的工作方式是根据原点 zf 的大小分配颜色。这意味着表面的着色方式现在与 zf 的实际大小无关。例如,二维极坐标图中没有负值,而旋转显然会生成相对于参考系原点具有负坐标的点。
这应该是一个简单的操作,但我不知何故卡住了......
感谢您对此的任何见解!
解决方法
mesh
命令接受 another argument to define colors:一种方法是为每个顶点定义一种颜色,在您的情况下,您仍然可以通过使用半径 R
来使用自动颜色图作为颜色:
mesh(xf,yf,zf,repmat(R',size(phi)))