
Plotting a hexagon consisting of triangles
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi there,
I am having some trouble plotting a hexagon which has triangles inside it as it can be seen in the figure I have attached. I have a 2D array with the nodepoints (x,y) following the shape first around the perimeter of the hexagon before going into the figure for the triangles as indicated in the figure. Now I hav some issues plotting it using a line plot as I have points connected that I don't want to connect as matlab is reading the array top to bottom connectiong the consecutive points. Any help would be greatly appreatiated!!
Cheers!
2 Kommentare
Image Analyst
am 25 Dez. 2020
Why does your image have a range of values specified in blue for the length of each side of the "hexagon" shape? Anyway, just use sin() and cos() to get the coordinates, and then call plot(). No big deal. But you have to know the length of each side (hence my question about that).

Antworten (1)
Image Analyst
am 25 Dez. 2020
Did you try this?
angles = 30:60:390;
sideLength = 10;
x1 = sideLength * cosd(angles);
y1 = sideLength * sind(angles);
% Add zeros so it goes back to the origin between each outer side.
x2 = [x1; zeros(1, length(x1))]
y2 = [y1; zeros(1, length(y1))]
x3 = [x1(:); reshape(x2, [], 1)]
y3 = [y1(:); reshape(y2, [], 1)]
plot(x3, y3, 'b-', 'lineWidth', 3);
grid on;
axis square;

2 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!