-2
我想沿着六角形轨迹移动星形标记,类似于我在问题末尾添加的“圆形轨迹”。谢谢。沿六角形轨迹移动星形标记?
这是源代码,我写了又创造同心hegzagons,但我不知道如何移动星标记横穿同心六边形,我写了一个类似的模拟代码为圆形轨道,但我无法做到六角形。
%clc; % Clear the command window.
%close all; % Close all figures (except those of imtool.)
%clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
angles = linspace(0, 360, 7);
radii = [20, 35, 50,70];
% First create and draw the hexagons.
numberOfHexagons = 4;
% Define x and y arrays. Each row is one hexagon.
% Columns are the vertices.
x1=radii(1) * cosd(angles)+50;
y1 = radii(1) * sind(angles)+50;
x2=radii(2) * cosd(angles)+50;
y2 = radii(2) * sind(angles)+50;
x3=radii(3) * cosd(angles)+50;
y3 = radii(3) * sind(angles)+50;
x4=radii(4) * cosd(angles)+50;
y4 = radii(4) * sind(angles)+50;
plot(x1 , y1, 'b');
hold on
plot(x2, y2, 'b');
hold on
plot(x3, y3, 'b');
hold on
plot(x4, y4, 'b');
hold on
% Connecting Line:
plot([70 100], [50 50],'color','b')
axis([0 100 0 100])
hold on
圆轨迹:
% Initialization steps.
format long g;
format compact;
fontSize = 20;
r1 = 50;
r2 = 35;
r3= 20;
xc = 50;
yc = 50;
% Since arclength = radius * (angle in radians),
% (angle in radians) = arclength/radius = 5/radius.
deltaAngle1 = 5/r1;
deltaAngle2 = 5/r2;
deltaAngle3 = 5/r3;
theta1 = 0 : deltaAngle1 : (2 * pi);
theta2 = 0 : deltaAngle2 : (2 * pi);
theta3 = 0 : deltaAngle3 : (2 * pi);
x1 = r1*cos(theta1) + xc;
y1 = r1*sin(theta1) + yc;
x2 = r2*cos(theta2) + xc;
y2 = r2*sin(theta2) + yc;
x3 = r3*cos(theta3) + xc;
y3 = r3*sin(theta3) + yc;
plot(x1,y1,'color',[1 0.5 0])
hold on
plot(x2,y2,'color',[1 0.5 0])
hold on
plot(x3,y3,'color',[1 0.5 0])
hold on
% Connecting Line:
plot([70 100], [50 50],'color',[1 0.5 0])
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]);
drawnow;
axis square;
for i = 1 : length(theta1)
plot(x1(i),y1(i),'r*')
pause(0.1)
end
for i = 1 : length(theta2)
plot(x2(i),y2(i),'r*')
pause(0.1)
end
for i = 1 : length(theta3)
plot(x3(i),y3(i),'r*')
pause(0.1)
end
什么是你的问题? – excaza
[为什么“有人可以帮助我?”不是一个真正的问题?](http://meta.stackoverflow.com/q/284236)此外,倾销你的代码的A部分,并要求我们写没有你显示B部分对B部分的任何努力或研究在这里都不是很好理解。 – Adriaan
感谢您的评论,但我真的试图自己做,但不幸的是我不能,我没有选择,只能在这里问我的问题,而且我没有让A部分要求你写B部分,如果你仔细阅读我的问题,你会知道我已经写了B部分来绘制圆形轨迹,其中红色星形标记遍历同心圆,现在我想编写代码来创建六边形轨迹的类似情况,但是我有写它的问题代码,我写了只能创建同心六边形的代码。 – zein