斜纹的代码错了,请重新编写,竹编的用六边形竹编,也重新写一下
- User
斜纹的代码错了,请重新编写,竹编的用六边形竹编,也重新写一下
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
斜纹的代码错了,请重新编写,竹编的用六边形竹编,也重新写一下
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
下面给出两段 Matlab 代码:
两段代码都遵守“十个单元以内”的范围,并且 每根经(纵向)/纬(横向)或每组竹篾均用不同颜色标识,便于观察。
思路
• 10 根经线 + 10 根纬线;
• 浮点规律:warp over 2, under 2,每行(纬)右移 1 格产生斜纹;
• 先画整条纬线(在下层),再按浮点规则把“在上层”的经线段覆盖上去;
• 为了确保所有线条可区分,分别调用 lines() 和 hsv() 生成 10 种颜色。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2/2 T W I L L (10 x 10 cells, different colours) %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; clear; clc;
n = 10; % 单元格数
cell_w = 1; % 单元边长
gap = 0.15; % 让线条不完全贴边,观感更好
warp_col = lines(n); % 10 种颜色的经线
weft_col = hsv(n); % 10 种颜色的纬线
figure('Color','w'); hold on; axis equal off;
xlim([0 n]); ylim([0 n]);
%% 1) 先画纬线(在底层)
for j = 1:n
y = n - j + 0.5; % 让 (0,0) 在左下角
plot([0 n], [y y], ...
'Color', weft_col(j,:), ...
'LineWidth', 2);
end
%% 2) 根据 2/2 斜纹浮位规律分段画经线(在上层)
% 规则:warp(i,j) 在上 <=> mod(i - j, 4) == 0 或 1
for i = 1:n
x = i - 0.5; % 经线的 x 坐标
for j = 1:n
cond = mod(i - j, 4); % 浮位判定
if cond==0 || cond==1 % warp 在上
y0 = n - j + gap; % 当前单元的下边
y1 = n - (j-1) - gap; % 当前单元的上边
plot([x x],[y0 y1], ...
'Color', warp_col(i,:), ...
'LineWidth', 4); % 粗一点以示“浮”
end
end
end
title('2/2 斜纹织物 (warp over 2, under 2)', ...
'FontWeight','bold','FontSize',12);
运行效果
• 每根经线、纬线颜色均不同;
• 浮点对角线清晰、无错位。
思路
• 竹编通常由 3 组方向互差 60° 的竹篾交织,形成蜂巢状空隙;
• 这里给出 10×10 的示意区域(大约能排布 4~5 行六边形);
• 每组方向(A/B/C)用一套渐变色,保证“不同篾条颜色不同”;
• 为简洁,只画竹篾中心线(可以把 LineWidth 调粗看成竹篾带宽)。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% H E X A G O N A L B A M B O O W E A V E %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; clear; clc;
L = 10; % 可视窗口大小
s = 1; % 正六边形边长 (= 竹篾交点间距)
dx = 1.5*s; % 同一水平行相邻六边形中心距
dy = sqrt(3)*s; % 相邻行中心距 (60°网格)
figure('Color','w'); hold on; axis equal off;
xlim([0 L]); ylim([0 L]);
% 生成三套颜色,各 15 根足够用
colA = parula(15); % 0° (水平)
colB = hot(15); % +60°
colC = cool(15); % -60°
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1) 0° 方向(水平)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
idx = 1;
for y = 0 : dy/2 : L
plot([0 L], [y y], 'Color', colA(idx,:), 'LineWidth',2);
idx = idx + 1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2) +60° 方向
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
idx = 1;
% 直线方程组: y = sqrt(3)*(x - c),枚举截距 c
for c = -L : s : L*2
x = [-1 L+1]; % 超出一点画长线再统一裁剪
y = sqrt(3)*(x - c);
plot(x, y, 'Color', colB(idx,:), 'LineWidth',2);
idx = idx + 1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3) -60° 方向
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
idx = 1;
% 直线方程: y = -sqrt(3)*(x - c)
for c = -L : s : L*2
x = [-1 L+1];
y = -sqrt(3)*(x - c);
plot(x, y, 'Color', colC(idx,:), 'LineWidth',2);
idx = idx + 1;
end
title('六边形竹编 (Hexagonal Bamboo Weave)', ...
'FontWeight','bold','FontSize',12);
% 裁剪显示范围
axis([0 L 0 L]);
调整要点
s 控制六边形大小;LineWidth 调成 4–6,视觉更像竹篾;dx, dy, 以及循环步长。twill_2over2.m 和 hex_bamboo.m,或直接粘贴到 Matlab 命令窗口运行;subplot 即可。祝编织几何可视化顺利!🎨
请给出平纹,斜纹,缎纹,中国结编织和竹编(六边形)还有绕编的几何构型(限制五个单元内)可视化代码(matlab),其中,为了更加直观,经纬线用条带表示,并且这些编织方式均留有一定的孔隙
下面是一整份 Matlab 示例脚本,按 subplot(2,3) 布局依次绘制
① 平纹 ② 2/2 斜纹 ③ 5梭口缎纹 ④ 中国结 ⑤ 六边形竹编 ⑥ 绕编
• 仅演示 5 × 5 单元(或等效尺寸)
• “条带” 用 patch(矩形/平行四边形)或粗 line 表示,条带之间留出 gap 形成孔隙
• 每根经/纬(或每组竹篾)颜色不同,易于观察“浮沉”关系
• 所有坐标均归一到 [0,5] 区域,便于统一缩放
直接把下面代码整段复制到 Matlab 脚本运行即可。
如果只想看某一种织物,把其余部分用%%选中后Ctrl+R注释即可。
%% ==============================================================
% 多种织物(5單元內)幾何構型可視化 —— Matlab 2024
% ① Plain ② Twill(2/2) ③ Satin(5H) ④ Chinese Knot
% ⑤ Hex-bamboo ⑥ Coiling
% 主要演示 • 條帶顏色區分 • 保留孔隙
% ---------------------------------------------------------------
clear; close all; clc;
figure('Color','w','Position',[50 50 1400 800]);
%% 通用參數
N = 5; % 單元數
cellW = 1; % 每單元邊長
strip = 0.8; % 條帶寬度 (單元長度的比例)
g = (1-strip)/2;% gap = 孔隙寬度 (條帶與單元邊之間)
hw = strip/2; % half width
warpCol = lines(N); % N種顏色:經
weftCol = hsv(N); % N種顏色:緯
%% ==============================================================
% ① P L A I N W E A V E ------------------------------------
subplot(2,3,1); hold on; axis equal off; title('① 平纹 (Plain)');
xlim([0 N]); ylim([0 N]);
% ---1) 先畫整條 【緯線(在底層)】--------------------------------
for j = 1:N
y = j - 0.5;
patch([0 N N 0], y + [-hw -hw hw hw], ...
weftCol(j,:), 'EdgeColor','none');
end
% ---2) 再畫整條 【經線】------------------------------------------
for i = 1:N
x = i - 0.5;
patch(x + [-hw -hw hw hw], [0 0 N N], ...
warpCol(i,:), 'EdgeColor','none');
end
% ---3) 按 “一上一下” 規則補覆蓋層 -------------------------------
for i = 1:N
for j = 1:N
x = i - 0.5; % 經線中心
y = j - 0.5; % 緯線中心
if mod(i+j,2)==0 % 經浮
% 讓經線在該單元內覆蓋緯線
patch(x + [-hw -hw hw hw], ...
y + [-0.5+g -g g 0.5-g], ...
warpCol(i,:), 'EdgeColor','none');
else % 緯浮
patch([i-1+g i-g i-g i-1+g], ...
y + [-hw -hw hw hw], ...
weftCol(j,:), 'EdgeColor','none');
end
end
end
%% ==============================================================
% ② 2 / 2 T W I L L ----------------------------------------
% 規則:warp over-2 under-2 ,每行右移1格
subplot(2,3,2); hold on; axis equal off; title('② 2/2 斜纹 (Twill)');
xlim([0 N]); ylim([0 N]);
% 底層:全部緯線
for j = 1:N
y = j - 0.5;
patch([0 N N 0], y + [-hw -hw hw hw], ...
weftCol(j,:), 'EdgeColor','none');
end
% 經線底層(讓“沉”也可見):
for i = 1:N
x = i - 0.5;
patch(x + [-hw -hw hw hw], [0 0 N N], ...
warpCol(i,:), 'EdgeColor','none');
end
% 浮沉判定:warp 在上 ⇔ mod(i-j,4)∈{0,1}
for i = 1:N
for j = 1:N
if ismember(mod(i - j,4),[0 1]) % warp 浮 2
x = i - 0.5;
y = j - 0.5;
patch(x + [-hw -hw hw hw], ...
y + [-0.5+g -g g 0.5-g], ...
warpCol(i,:), 'EdgeColor','none');
else % weft 浮 2
patch([i-1+g i-g i-g i-1+g], ...
(j-0.5)+[-hw -hw hw hw], ...
weftCol(j,:), 'EdgeColor','none');
end
end
end
%% ==============================================================
% ③ 5-HARNESS S A T I N (經面 5H) ----------------------------
% 浮規律:i 行 -> 浮點列序列 0, 2, 4, 1, 3 (移2位)
subplot(2,3,3); hold on; axis equal off; title('③ 5梭口缎纹 (Satin 5H)');
xlim([0 N]); ylim([0 N]);
% 全部緯線底層
for j = 1:N
y = j - 0.5;
patch([0 N N 0], y + [-hw -hw hw hw], ...
weftCol(j,:), 'EdgeColor','none');
end
% 經線底層
for i = 1:N
x = i - 0.5;
patch(x + [-hw -hw hw hw], [0 0 N N], ...
warpCol(i,:), 'EdgeColor','none');
end
% 浮點:col = mod( 2*(row-1) , 5 ) 0-4
for j = 1:N
col = mod(2*(j-1),5)+1; % 1—5 對應列
% 經線在 (col , j) 浮
x = col - 0.5;
y = j - 0.5;
patch(x + [-hw -hw hw hw], ...
y + [-0.5+g -g g 0.5-g], ...
warpCol(col,:), 'EdgeColor','none');
end
%% ==============================================================
% ④ C H I N E S E K N O T ----------------------------------
% 用圓環+對角交叉模擬,留大孔隙
subplot(2,3,4); hold on; axis equal off; title('④ 中国结 (Chinese Knot)');
xlim([0 N]); ylim([0 N]);
theta = linspace(0,2*pi,200);
r_in = 0.25; % 環半徑
for i = 1:N
for j = 1:N
cx = i-0.5; cy = j-0.5;
% 主環 (紅)
fill( cx + r_in*cos(theta), ...
cy + r_in*sin(theta), ...
[1 0.4 0.4], 'EdgeColor','none' );
% 斜向纏繞 (藍)
t2 = theta + pi/4;
fill( cx+0.1 + r_in*cos(t2), ...
cy+0.1 + r_in*sin(t2), ...
[0.4 0.4 1], 'EdgeColor','none' );
end
end
%% ==============================================================
% ⑤ H E X A G O N A L B A M B O O --------------------------
subplot(2,3,5); hold on; axis equal off; title('⑤ 六边形竹编 (Hex-Bamboo)');
xlim([0 N]); ylim([0 N]);
% 參數
wB = 0.25; % 竹篾條帶寬
L = N + 1; % 畫條帶長度
ang = 60*pi/180; % 60°
dir = [0 ang -ang]; % 三方向
pal = [parula(7); hot(7); cool(7)]; % 顏色池
idx = 1;
for d = 1:3
a = dir(d);
% 在方向 a 上以步長 s = 1 畫平行線
sMax = ceil(L/0.5);
for k = -sMax:sMax
% 直線方程 n·r = c
n = [cos(a+pi/2) sin(a+pi/2)];
c0 = k*0.5;
% 找到兩點交邊界
pts = [];
for x = [-1 L+1]
y = (c0 - n(1)*x)/n(2);
pts = [pts; x y];
end
for y = [-1 L+1]
x = (c0 - n(2)*y)/n(1);
pts = [pts; x y];
end
% 取在顯示範圍附近的兩點
pts = pts(~any(isnan(pts),2),:);
% 延長一點再裁剪
p1 = pts(1,:); p2 = pts(2,:);
v = p2-p1; v = v/norm(v);
p1 = p1 - v*1; p2 = p2 + v*1;
% 用平行四邊形做成“帶”
nside = [ -v(2) v(1) ]; % 與線垂直單位向量
quad = [p1; p2; p2+wB*nside; p1+wB*nside];
fill(quad(:,1), quad(:,2), pal(idx,:), 'EdgeColor','none');
idx = idx + 1;
if idx>size(pal,1), idx=1; end
end
end
axis([0 N 0 N]);
%% ==============================================================
% ⑥ C O I L I N G W E A V E --------------------------------
subplot(2,3,6); hold on; axis equal off; title('⑥ 绕编 (Coiling)');
xlim([0 N]); ylim([0 N]);
th = linspace(0,6*pi,800);
r = 0.15*th; % 螺旋半徑增長
x1 = N/2 + r.*cos(th);
y1 = N/2 + r.*sin(th);
x2 = N/2 + r.*cos(th+pi/2);
y2 = N/2 + r.*sin(th+pi/2);
% 用粗線模擬條帶
plot(x1,y1,'r','LineWidth',25,'Color',[1 0.3 0.3]);
plot(x2,y2,'b','LineWidth',15,'Color',[0.3 0.3 1]);
% 留中心孔隙
rectangle('Position',[N/2-0.5 N/2-0.5 1 1], ...
'Curvature',[1 1], 'FaceColor','w', 'EdgeColor','none');
axis([0 N 0 N]);
%% ==============================================================
sgtitle('5 × 5 织物几何构型(条带 + 孔隙示意)','FontSize',14,'FontWeight','bold');
运行效果
• 各 subplot 都在 0–5 × 0–5 范围内;
• 条带宽度 strip=0.8,条带之间 & 条带与边缘的 gap 保留了可见孔隙;
• 颜色采用 lines / hsv / parula / hot / cool 渐变,让“每根条带/竹篾”都能区分;
• 对于竹编使用 三组 60° 平行四边形,显示典型的蜂巢空隙;
• 绕编用两条粗螺旋(红 + 蓝)演示缠绕,同时在中心挖去一个圆孔。
想要更宽的条带或更大的孔隙,只需调节 strip 与 g;
同理,改变 N 可以测试 3 × 3、4 × 4 等更小尺寸。
Happy weaving & visualizing! 🎨