Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7878843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:46:18+00:00 2026-06-03T03:46:18+00:00

I’m trying to create a close packed layer by generating my center points like

  • 0

I’m trying to create a close packed layer by generating my center points like a box and then shear the point in order to create a close packed layer of circles..
more info can be found here

but I’m having some difficulties.. My code so far is

%% 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

sorta packed circles

Don’t really understand the math behind the Sh, but can just see that it does a damn good job twisting (shearing) points. I calculated a slope of square root 3 should give the right place, but it looks lige there is something wrong with my y distances…

the circle function is

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

* SOLUTION *

%% 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

(don’t forget to vote up if you found it useful)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:46:19+00:00Added an answer on June 3, 2026 at 3:46 am

    By my reckoning your mistake (or perhaps just the first one that I can see) is in the y-spacing of the lines of circle centres. You have the expression

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

    for laying out the circle centres. I think that the vertical stride (or step value) should be rad*sqrt(3)/2 which would give you:

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

    Unless I’ve made a mistake (entirely possible) the height of a unit equilateral triangle is sqrt(3)/2 and that ought to be your y-spacing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.