将平面弯曲成圆锥曲面

时间:2015-05-20 21:38:46

标签: matlab

我目前正在尝试在Matlab上计算Origami结构,我正在寻找一种方法来在圆锥曲面上弯曲我的折痕图案,就像这个答案:Bending a plane into a closed surface/cylinder进入圆柱体一样。

我该怎么办呢?

干杯,

1 个答案:

答案 0 :(得分:2)

您只需将(x,y)坐标映射到圆锥曲面的3D坐标即可。因此,要做到这一点,将锥面作为两个变量的函数进行参数化非常重要。因此:

(r,theta,z)=( a * z + c ,theta,z)某些 a c 你定义

然后你只需要在(x,y)和(theta,z)之间创建一个关系,这样就可以找到一个给定的(theta,z)作为(x,y)的函数。然后它归结为一组简单的for循环迭代通过(x,y)点以找到锥形表面上的映射坐标。

===编辑===

所以我写了一些代码来说明映射有多简单。首先,这是一些图像。第一个是将被映射的平面网格,第二个图像是结果。

enter image description here enter image description here

% This is file: gen_mesh.m
function [x, y, tri_mesh] = gen_mesh()

% Initialize output coordinates of points that make up the mesh
y = [];
x = [];

% Initialize mesh
tri_mesh= [];

% Number of points in the x dimension
Nx = 5;

% Number of points in the y dimension
Ny = 17;

% For this mesh, make each row have a slightly
% different number of points
x1 = linspace(0,1,Nx);
dx = x1(2)-x1(1);
x2 = linspace(dx/2, 1-dx/2, Nx-1);

% Create the array with the y values
y1 = linspace(0,1,Ny);


%% Generate the associated (x,y) pairs
for iy = 1:Ny
   if( mod(iy,2) == 0 )
       y = [y, ones(1,Nx-1)*y1(iy)];
       x = [x, x2];
   else
       y = [y, ones(1,Nx)*y1(iy)];
       x = [x, x1];
   end
end


%% Generate the Mesh of triangles
% Make sure that the mesh wraps to each 
% opposite x bound. This is to make sure that
% the cyclic nature of the conical surface 
% doesnt mess up the look of the mesh
count = 1;

curr = 1;
ol = [];
el = [];
for iy = 1:Ny

    if( mod(iy, 2) == 0 )
        el.x = x(curr:curr+(Nx-2));
        el.y = y(curr:curr+(Nx-2));
    else

        ol.x = x(curr:curr + Nx - 1);
        ol.y = y(curr:curr + Nx - 1);
    end



    if( iy ~= 1 )
        for i = 2:Nx
            tri_mesh(count).x = [ol.x(i), el.x(i-1), ol.x(i-1)];
            tri_mesh(count).y = [ol.y(i), el.y(i-1), ol.y(i-1)];
            count = count + 1;
        end

        for i = 2:(Nx-1)
            tri_mesh(count).x = [el.x(i), ol.x(i), el.x(i-1)];
            tri_mesh(count).y = [el.y(i), ol.y(i), el.y(i-1)];
            count = count + 1;
        end

        tri_mesh(count).x = [el.x(1), ol.x(1), el.x(end)];
        tri_mesh(count).y = [el.y(1), ol.y(1), el.y(end)];
        count = count + 1;
    end



    if( mod(iy, 2) == 0 )
        curr = curr + (Nx-1);
    else
        curr = curr + Nx;
    end
end

end











% This is file: map_2D_to_3DCone.m
function [xh, yh, z] = map_2D_to_3DCone( x, x_rng, y, y_rng )
% x: an array of x values part of a planar coordinate
%
% x_rng: the smallest and largest possible x values in the planar domain
% ->  x_rng = [min_x, max_x]
%
% y: an array of y values part of a planar coordinate
%
% y_rng: the smallest and largest possible y values in the planar domain
% ->  y_rng = [min_y, max_y]


% The bottom z (height) value
zb = 0;

% The top z value
zt = 1;

% The radius value at z = zb
rb = 3;

% The radius value at z = zt
rt = 1;





%% Obtain the Conical Surface 3D coordinates

% Find z as a function of y in the planar domain
% This mapping is a simple 1-D Lagrange interpolation
z = (zt*( y - y_rng(1) ) - zb*( y - y_rng(2) ))/(diff(y_rng));

% Find the parametrized angle as a function of x
% using a 1D Lagrange interpolation
theta = 2*pi*( x - x_rng(1) )/(diff(x_rng));

% Find the radius as a function of z using
% a simple 1D legrange interpolation
r = ( rt*(z - zb) - rb*(z - zt) )/( zt - zb );



% Find the absolute x and y components of the
% 3D conical coordinates
xh = r.*cos(theta);
yh = r.*sin(theta);


end




% This is in file: PlaneMesh_to_ConicalMesh.m
function mesh3d = PlaneMesh_to_ConicalMesh( mesh2d )
% Generate the 3D version of each planar triangle, based
% on the mapping function that takes an (x,y) planar
% coordinate and maps it onto a conical surface
N = length(mesh2d);
mesh3d(N).x = [];
mesh3d(N).y = [];
mesh3d(N).z = [];


for i = 1:N
    [xh, yh, z] = map_2D_to_3DCone( mesh2d(i).x, [0,1], mesh2d(i).y, [0,1] );
    mesh3d(i).x = xh;
    mesh3d(i).y = yh;
    mesh3d(i).z = z;
end


end





% This is in file: gen3D_MappedCone.m
% Generate the 3D object
close all

% Generate a 2D planar mesh to morph onto
% a conical surface
[x, y, mesh2d] = gen_mesh();

% Map the 2D mesh into a 3D one based on the
% planar to conical surface mapping
mesh3d = PlaneMesh_to_ConicalMesh( mesh2d );

% Obtain the number of triangles making up 
% the mesh
N = length(mesh3d);


% Define a color mapping function for the sake
% of visualizing the mapping
color_map = @(x) [1, 0, 0].*(1-x) + [0, 0, 1].*x;




% Create the first image based on the planar
% mesh

figure(1)
hold on
for i = 1:N
   color = color_map( (i-1)/(N-1) );
   h = fill( mesh2d(i).x,mesh2d(i).y, color );
   set(h, 'facealpha',0.9)
end
axis([0,1,0,1])





% Create the next figure showing the 3D mesh
% based on the planar to conical surface transformation
figure(2)
hold on

for i = 1:N
    color = color_map( (i-1)/(N-1) );
    h = fill3(mesh3d(i).x,mesh3d(i).y,mesh3d(i).z, color);
    set(h, 'facealpha',0.9)
end

grid on
hold off