如何参数化弯曲圆柱体? [英] How to parameterize a curved cylinder?
问题描述
我想生成一个弯曲的圆柱体.例如,轴为正弦曲线或圆.
I want to generate a curved cylinder. For example, with axis being a sine curve or a circle.
我可以得到一个笔直的圆柱体
I can get a straight cylinder as follows
% Parameters
r=5; l=5; nTheta=100;
theta = 2*pi*(linspace(0,1,nTheta+1));
x = r * cos(theta);
x(end) = []; % Last element is same as first. So, just remove it
y = r * sin(theta);
y(end) = [];
z = repmat((0:l-1)', 1, nTheta);
% Plot
surf(repmat(x,l,1),repmat(y,l,1),z);
提供圆柱体,如果第9行更改为
gives a cylinder and if the 9th line is changed to
z = (0:l-1)' * sin(linspace(-pi,pi,nTheta));
我认为应该给我一个以正弦曲线为轴的圆柱体.但是,它给了我现在,我知道参数设置错误.将圆柱体沿正弦轴作为轴的正确参数设置是什么?
which I think should give me a cylinder with sine curve as axis. But, it gives me Now, I know that the parameterization is wrong. What would be the right parameterization to get a cylinder along a sine as axis?
推荐答案
首先,您应该指定圆柱轴的方向.现在,我将假定它指向z方向,并且仅沿x方向振动(即,轴的方程式为x = sin(z)
和y=0
).
First, you should specify the orientation of the axis of the cylinder. For now, I'm going to assume it's pointed in the z-direction, and that it's going to oscillate only in the x-direction (i.e. The equation of the axis is x = sin(z)
and y=0
).
如果圆柱体的轴随z
改变,则圆柱体表面的x,y
坐标也应为z
的函数.为此,您可以像以前一样先计算直圆柱体的x,y
点,然后添加一个依赖于本地z
值的移位".
If the cylinder's axis changes with z
, then the x,y
coordinates of the cylinder's surface should also be functions of z
. You can do this by first computing the x,y
points for the straight cylinder like you have already done, and then adding a "shift" that depends on the local z
value.
代码如下:
% Parameters
r=5; l=5; nTheta=100, nL = 20;
theta = linspace(0,2*pi,nTheta+1);
x = r * cos(theta);
y = r * sin(theta);
z = linspace(0,l,nL)';
xshift = repmat( sin(z), 1, nTheta+1); %this is a function of z
X = repmat(x,nL,1) + xshift;
Y = repmat(y,nL,1);
Z = repmat(z, 1, nTheta+1);
% Plot
surf(X,Y,Z)
如果圆柱体的轴在x和y方向上都发生振荡(或弯曲),则还需要yshift
.
You will also need a yshift
if the axis of the cylinder oscillates (or curves) in both x- and y-directions.
这篇关于如何参数化弯曲圆柱体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!