Plotting using given coordinates
Ältere Kommentare anzeigen
The x,y cooridnates are given in below matrix:
Nodes_stacked = [
6.3480 3.6650;
0 7.3300;
-6.3480 3.6650;
-6.3480 -3.6650;
0 -7.3300;
6.3480 -3.6650;
12.6960 14.6600;
6.3480 18.3250;
0 14.6600;
0 7.3300;
6.3480 3.6650;
12.6960 7.3300
];
However i used the following code to plot, but the hexagons arent getting closed up.Any remedy?
% Extract x and y coordinates
x = Nodes_stacked(:, 1);
y = Nodes_stacked(:, 2);
% Plot the coordinates and connect them with lines
plot(x, y, 'o-');
xlabel('X Coordinates');
ylabel('Y Coordinates');
title('Plot of Coordinates');
Akzeptierte Antwort
Weitere Antworten (1)
Are all the nodes the same distance from the center of your hexagon at (0, 0)?
Nodes_stacked = [
6.3480 3.6650;
0 7.3300;
-6.3480 3.6650;
-6.3480 -3.6650;
0 -7.3300;
6.3480 -3.6650;
12.6960 14.6600;
6.3480 18.3250;
0 14.6600;
0 7.3300;
6.3480 3.6650;
12.6960 7.3300
];
N = vecnorm(Nodes_stacked, 2, 2)
Okay, so the first few points (with radius around 7.33) are the lower-left hexagon and the others are for the upper-right hexagon? Let's see if we can recreate that first hexagon a different way, using a regular six-sided polygon.
R = N(1);
P = nsidedpoly(6, 'Radius', R);
Does this look similar to your lower-left hexagon?
plot(P)
axis([-10 15 -10 20])
No, but it looks like a rotated version. Let's rotate it by 30 degrees and see if it looks closer to what you showed.
P2 = rotate(P, 30);
figure
plot(P2)
axis([-10 15 -10 20])
That does. What does making this a polyshape object get us? We can rotate it with the rotate function, make copies by translating it, and do other transformations to it. See the polyshape documentation page and look at the list of "Object Functions" for more capabilities you can use to manipulate those objects.
P3 = translate(P2, [0 2*R]); % Make a copy of P2 with its center at (0, 2*R) instead of (0, 0)
figure
plot(P2) % The original
hold on
plot(P3, 'FaceColor', 'r') % The copy
axis equal
Now I could create an array [P2, P3] and translate both in one call to translate.
If you want the coordinates, you can ask for the Vertices property of the object.
coordinates = P2.Vertices
Those numbers look close to the entries in Nodes_stacked, albeit in a slightly different order.
5 Kommentare
Nupur
am 7 Jul. 2023
Steven Lord
am 7 Jul. 2023
This was just intended to demonstrate how to translate a polyshape. You could adjust the offset to translate it differently.
Nupur
am 7 Jul. 2023
Nupur
am 7 Jul. 2023
Nupur
am 7 Jul. 2023
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




