0

我正在尝试通过像一个盒子一样生成我的中心点来创建一个紧密堆积的层,然后剪切该点以创建一个紧密堆积的圆圈层。 更多信息可以在这里找到

但我遇到了一些困难..到目前为止我的代码是

%% Trying out the shear function
rad=2; n=3;
[X,Y] = meshgrid(0   :   rad*2   :   rad*(n-1)*2    ,   ...
             0   : sqrt(2*(2*rad)^2)/2 : sqrt(2*(2*rad)^2)/2*(n-1));
xyBox = [reshape(X,1,numel(X)) ; reshape(Y,1,numel(Y))];
Sh = @(m) [1 m; 0 1];       % horizontal shear - slope is qual to 1/m
slope = sqrt(3);

shearedCoordinates = Sh(1/slope) * xyBox;
figure; plot(xyBox(1,:),xyBox(2,:),'k.');
for i= 1:(numel(shearedCoordinates)/2)
    hold on;
    circle(shearedCoordinates(1,i),shearedCoordinates(2,i),rad)
    plot(shearedCoordinates(1,i),shearedCoordinates(2,i),'bx')
    hold off;
end
axis equal

有点拥挤的圈子

不太了解 Sh 背后的数学原理,但可以看出它在扭曲(剪切)点方面做得非常好。我计算出平方根 3 的斜率应该给出正确的位置,但看起来我的 y 距离有问题......

圆函数是

function circle(x,y,r)
    angle=0:0.01:2*pi; 
    xp=r*cos(angle);
    yp=r*sin(angle);
    plot(x+xp,y+yp,'r');
end

* 解决方案 *

%% Trying out the shear function
rad=2; n=3;
[X,Y] = meshgrid(0   :   rad*2   :   rad*(n-1)*2    , ...
    0   : sqrt(3)*rad   : sqrt(3)*rad*(n-1));
xyBox = [reshape(X,1,numel(X)) ; reshape(Y,1,numel(Y))];
Sh = @(m) [1 m; 0 1];       % horizontal shear - slope is qual to 1/m
slope = sqrt(3);

shearedCoordinates = Sh(1/slope) * xyBox;
figure; plot(xyBox(1,:),xyBox(2,:),'k.');
for i= 1:(numel(shearedCoordinates)/2)
    hold on;
    circle(shearedCoordinates(1,i),shearedCoordinates(2,i),rad)
    plot(shearedCoordinates(1,i),shearedCoordinates(2,i),'bx')
    hold off;
end
axis equal

(觉得有用别忘了点赞哦)

4

2 回答 2

0

我还没有机会通过 Matlab 中的代码,但只要看看你发布的图,我同意剪切正在工作。但是,即使您使用预剪切中心,这些圆圈也会重叠。你是这个意思吗?

于 2012-05-01T14:17:29.377 回答
0

我认为您的错误(或者可能只是我能看到的第一个错误)在于圆心线的 y 间距。你有表情

0   : sqrt(2*(2*rad)^2)/2 : sqrt(2*(2*rad)^2)/2*(n-1)

用于布置圆心。我认为垂直步幅(或步长值)应该rad*sqrt(3)/2会给你:

0   : rad*sqrt(3)/2 : sqrt(2*(2*rad)^2)/2*(n-1)

除非我犯了一个错误(完全可能),否则单位等边三角形的高度sqrt(3)/2应该是你的 y 间距。

于 2012-05-01T14:23:15.467 回答