【问题标题】:Bending a plane into a conical surface将平面弯曲成圆锥面
【发布时间】:2015-05-23 11:18:22
【问题描述】:

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

请问我该怎么做?

干杯,

【问题讨论】:

  • 这不是一个真正的具体问题和/或过于宽泛。你试过什么?向我们展示您正在尝试做什么以及哪里出错的示例代码。
  • 好问题,谢谢!

标签: matlab


【解决方案1】:

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

( r, theta, z ) = ( a * z + c, theta, z ) 对于一些 a, c你定义

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

=== 编辑 ===

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

% 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

【讨论】:

  • 有没有办法避免循环来做到这一点?我需要我的代码快速,因为我想要在 3Dplot 中将图案投影到圆锥上的折纸结构可以由许多点组成。我已经使用循环来确保“折叠”,所以需要很长时间。
  • 您需要做的唯一循环是在每个 (x,y) 坐标上循环,这样您就可以找到它的 3-D 圆锥坐标。这真的不是你能摆脱的东西。稍后我将尝试向您展示此工作的示例。我会将其发布为对我的答案的编辑。
  • 非常感谢。对不起,我不得不离开周末,我会在星期二回来更好地发表评论。您的代码是否也适用于这种螺旋模式? link。我设法编写了该模式。对不起我的代码结构。我开始了,确实我倾向于添加行而不是使用函数。
  • 此代码适用于任何一组 (x,y) 平面点。要制作完整的设计,您需要形成一个三角形网格,但如果你做得对,你就会被设置!
  • 感谢 choward 提供的代码,它运行良好。我尝试了由不等边三角形和等腰三角形组成的图案。不知道大家对折纸有兴趣吗?我正在寻找一个计算合作伙伴来帮助我计算我的 GUI 的结尾......如果你有空闲时间,我会很高兴......让我知道。 hpics.li/f2a670ehpics.li/e918add
猜你喜欢
  • 2014-12-12
  • 2019-11-05
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
  • 2013-12-27
  • 2012-08-21
  • 1970-01-01
相关资源
最近更新 更多