How to made my hexa like this??
1 回表示 (過去 30 日間)
古いコメントを表示
My code:
clc;
close all
clear all;
f=input('please enter the dim=')
t=linspace(0,2*pi,7);
for Z=[-f/2:1:f/2]
for j=-f/2:1.732:f/2
ao=((Z)*1.5)+1*cos(t);
bo=(j)+1*sin(t);
plot(ao,bo);
plot(Z*1.5,(j),'ro')
hold on
end
for k=-f/2:1.732:f/2
al=((-Z)*1.5)+1*cos(t);
bl=(k)+1*sin(t);
plot(al,bl);
plot(-Z*1.5,k,'ro')
hold on
end
end
the result when I enter dim=10 is hexa generated but overlapping each other and I want it matching for planning.
[Information merged from first duplicate]
This code generate fixed area of hexa and i need to make it changable
clc;
close all
clear all;
t=linspace(0,2*pi,7);
ahx=0+1*cos(t);
bhx=0+1*sin(t);
plot(ahx,bhx);
for i=-0.866:1.732:10
ah=0+1*cos(t);
bh=i+1*sin(t);
plot(ah,bh);
plot(0,i,'ro');
hold on
end
for j=1.732:1.732:10
ar=1.5+1*cos(t);
br=j+1*sin(t);
plot(ar,br);
plot(1.5,j,'ro')
hold on
end
for k=1.732:1.732:10
al=-1.5+1*cos(t);
bl=k+1*sin(t);
plot(al,bl);
plot(-1.5,k,'ro')
hold on
end
grid on
[Information merged from second duplicate]
i want to make this code with for loops and i cant change radius to any no except 1
close all
clear all
clc
%L=input('enter the length=')
r=input('enter the radius=')
ax=-1.732 %middle
ay=0
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on
hold on
ax=0
ay=0
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'y')
grid on
hold on
ax=1.732
ay=0
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on
ax=-1.732*2
ay=0
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'b')
grid on
hold on
ax=1.732*2
ay=0
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'b')
grid on
ax=-1.732*3
ay=0
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'y')
grid on
hold on
ax=1.732*3
ay=0
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on %end
ax=-1.732 %upper line
ay=3*r
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on
hold on
ax=0
ay=3*r
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'y')
grid on
hold on
ax=1.732
ay=3*r
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on
ax=-1.732*2
ay=3*r
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'b')
grid on
hold on
ax=1.732*2
ay=3*r
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'b')
grid on
ax=-1.732*3
ay=3*r
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'y')
grid on
hold on
ax=1.732*3
ay=3*r
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on %end
ax=-1.732 %lower line
ay=-3*r
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on
hold on
ax=0
ay=-3*r
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'y')
grid on
hold on
ax=1.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ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on %end
ax=-0.866 %first
ay=1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on
hold on
ax=0.866
ay=1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'b')
grid on
ax=-0.866*3
ay=1.5
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'y')
grid on
hold on
ax=0.866*3
ay=1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on
ax=-0.866*5
ay=1.5
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on
hold on
ax=0.866*5
ay=1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on %end
ax=-0.866 %second
ay=-1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on
hold on
ax=0.866
ay=-1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'b')
grid on
ax=-0.866*3
ay=-1.5
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'y')
grid on
hold on
ax=0.866*3
ay=-1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on
ax=-0.866*5
ay=-1.5
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on
hold on
ax=0.866*5
ay=-1.5
r1=sqrt(3)*r/2;
r2=+(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on %end
[Information merged from 3rd duplicate]
i want to change radius and make always the center(0,0)
close all
clear all
clc
L=input('enter the length x=')
N=input('enter the length y=')
r=input('enter the radius=')
for h=-(N)/2:3:(N)/2
for i=-L/2:1.732:L/2
ax=i %middle
ay=h
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'r')
grid on
hold on
end
end
for j=-(N-3)/2:3:(N-3)/2
for k=-(L+1.732)/2:1.732:(L+1.732)/2
ax=k %middle
ay=j
r1=sqrt(3)*r/2;
r2=(r/2);
A=[ax ay+r];
B=[ax+r1 ay+r2]
C=[ax+r1 ay-r2]
D=[ax ay-r]
E=[ax-r1 ay-r2]
F=[ax-r1 ay+r2]
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
fill(x,y,'g')
grid on
hold on
end
end
1 件のコメント
Walter Roberson
2012 年 2 月 20 日
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
回答 (2 件)
Walter Roberson
2012 年 1 月 31 日
t = linspace(0,2*pi,7);
f = input('please enter the (even) dim=')
clf
hold on
xlim([-f/2,f/2]);
ylim([-f/2,f/2]);
axis square
L = f/2 - 1;
Zp = -L : 2 : L;
jp = Zp * sqrt(3) / 2;
for Z = Zp
for j = jp
ao = Z + cos(t);
bo = j + sin(t);
plot(ao, bo);
plot(Z, j, 'ro')
end
end
Note: this graph will have the appearance that the hexagons are overlapped. They are not overlapped: it is an illusion that is partly generated because you wanted the hexagons lined up on a grid instead of being staggered like they are in a honeycomb.
2 件のコメント
Walter Roberson
2012 年 2 月 1 日
The code I gave does NOT overlap anything. It might _look_ like it does, but that is an illusion because all the lines are the same color.
Here is a minor modification to the routine to change the coloring so that you can see more clearly that there is no overlap.
t = linspace(0,2*pi,7);
f = input('please enter the (even) dim=');
clf
hold on
xlim([-f/2,f/2]);
ylim([-f/2,f/2]);
axis square
L = f/2 - 1;
Zp = -L : 2 : L;
jp = Zp * sqrt(3) / 2;
colord = 'bgkcmy';
colidx = 0;
for Z = Zp
for j = jp
colidx = mod(colidx,length(colord)) + 1;
ao = Z + cos(t);
bo = j + sin(t);
plot(ao, bo, colord(colidx));
plot(Z, j, 'ro')
end
end
Walter Roberson
2012 年 2 月 20 日
Your duplicate questions have been merged in to your original question, and the duplicate questions have been deleted.
Before anyone can assist you, you need to give a clear description of what you are trying to achieve. For example,
"I am attempting to project a Hexadecachoronic Honeycomb to two dimensions, from the 4-dimensional viewpoint [v1,v2,v3,v4], looking towards [w1,w2,w3,w4], and [...]"
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Engines & Motors についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!