Plotting using given coordinates
1 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
采纳的回答
Dyuman Joshi
2023-7-3
编辑:Dyuman Joshi
2023-7-22
The order of indices is not correct. I have corrected it -
Edit - Updated answer below for a bigger data set of points
%Modified array
Nodes_stacked = [
6.3480 3.6650;
0 7.3300;
-6.3480 3.6650;
-6.3480 -3.6650;
0 -7.3300;
6.3480 -3.6650;
6.3480 3.6650;
12.6960 7.3300;
12.6960 14.6600;
6.3480 18.3250;
0 14.6600;
0 7.3300;
6.3480 3.6650;
];
%The last point in the array is redundant, you can remove it
% Extract x and y coordinates
x = Nodes_stacked(:, 1);
y = Nodes_stacked(:, 2);
plot(x, y, 'o-');
xlabel('X Coordinates');
ylabel('Y Coordinates');
title('Plot of Coordinates');
5 个评论
Dyuman Joshi
2023-7-7
@Nupur I was asking about the significane of two columns mentioned in the excel file named 'Node Number 1' and 'Node Number 2'.
They are indeed useful -
%The coordinates of points
vertices = [6.348 3.665
0 7.33
-6.348 3.665
-6.348 -3.665
0 -7.33
6.348 -3.665
12.696 14.66
6.348 18.325
0 14.66
12.696 7.33
6.348 25.655
0 29.32
-6.348 25.655
-6.348 18.325
12.696 36.65
6.348 40.315
0 36.65
12.696 29.32
6.348 47.645
0 51.31
-6.348 47.645
-6.348 40.315
12.696 58.64
6.348 62.305
0 58.64
12.696 51.31
6.348 69.635
0 73.3
-6.348 69.635
-6.348 62.305
12.696 80.63
6.348 84.295
0 80.63
12.696 73.3
19.043 3.665
12.696 -7.33
19.043 -3.665
25.391 14.66
19.043 18.325
25.391 7.33
19.043 25.655
25.391 36.65
19.043 40.315
25.391 29.32
19.043 47.645
25.391 58.64
19.043 62.305
25.391 51.31
19.043 69.635
25.391 80.63
19.043 84.295
25.391 73.3
31.739 3.665
25.391 -7.33
31.739 -3.665
38.087 14.66
31.739 18.325
38.087 7.33
31.739 25.655
38.087 36.65
31.739 40.315
38.087 29.32
31.739 47.645
38.087 58.64
31.739 62.305
38.087 51.31
31.739 69.635
38.087 80.63
31.739 84.295
38.087 73.3
44.434 3.665
38.087 -7.33
44.434 -3.665
50.782 14.66
44.434 18.325
50.782 7.33
44.434 25.655
50.782 36.65
44.434 40.315
50.782 29.32
44.434 47.645
50.782 58.64
44.434 62.305
50.782 51.31
44.434 69.635
50.782 80.63
44.434 84.295
50.782 73.3
57.13 3.665
50.782 -7.33
57.13 -3.665
63.478 14.66
57.13 18.325
63.478 7.33
57.13 25.655
63.478 36.65
57.13 40.315
63.478 29.32
57.13 47.645
63.478 58.64
57.13 62.305
63.478 51.31
57.13 69.635
63.478 80.63
57.13 84.295
63.478 73.3
69.826 3.665
63.478 -7.33
69.826 -3.665
76.173 14.66
69.826 18.325
76.173 7.33
69.826 25.655
76.173 36.65
69.826 40.315
76.173 29.32
69.826 47.645
76.173 58.64
69.826 62.305
76.173 51.31
69.826 69.635
76.173 80.63
69.826 84.295
76.173 73.3
82.521 3.665
76.173 -7.33
82.521 -3.665
88.869 14.66
82.521 18.325
88.869 7.33
82.521 25.655
88.869 36.65
82.521 40.315
88.869 29.32
82.521 47.645
88.869 58.64
82.521 62.305
88.869 51.31
82.521 69.635
88.869 80.63
82.521 84.295
88.869 73.3
95.217 3.665
88.869 -7.33
95.217 -3.665
101.564 14.66
95.217 18.325
101.564 7.33
95.217 25.655
101.564 36.65
95.217 40.315
101.564 29.32
95.217 47.645
101.564 58.64
95.217 62.305
101.564 51.31
95.217 69.635
101.564 80.63
95.217 84.295
101.564 73.3];
%Array comprising the values of Node numbers as columns
faces = [1 2
2 3
3 4
4 5
5 6
1 6
7 8
8 9
2 9
1 10
7 10
11 12
12 13
13 14
9 14
8 11
15 16
16 17
12 17
11 18
15 18
19 20
20 21
21 22
17 22
16 19
23 24
24 25
20 25
19 26
23 26
27 28
28 29
29 30
25 30
24 27
31 32
32 33
28 33
27 34
31 34
10 35
6 36
36 37
35 37
38 39
7 39
35 40
38 40
18 41
39 41
42 43
15 43
41 44
42 44
26 45
43 45
46 47
23 47
45 48
46 48
34 49
47 49
50 51
31 51
49 52
50 52
40 53
37 54
54 55
53 55
56 57
38 57
53 58
56 58
44 59
57 59
60 61
42 61
59 62
60 62
48 63
61 63
64 65
46 65
63 66
64 66
52 67
65 67
68 69
50 69
67 70
68 70
58 71
55 72
72 73
71 73
74 75
56 75
71 76
74 76
62 77
75 77
78 79
60 79
77 80
78 80
66 81
79 81
82 83
64 83
81 84
82 84
70 85
83 85
86 87
68 87
85 88
86 88
76 89
73 90
90 91
89 91
92 93
74 93
89 94
92 94
80 95
93 95
96 97
78 97
95 98
96 98
84 99
97 99
100 101
82 101
99 102
100 102
88 103
101 103
104 105
86 105
103 106
104 106
94 107
91 108
108 109
107 109
110 111
92 111
107 112
110 112
98 113
111 113
114 115
96 115
113 116
114 116
102 117
115 117
118 119
100 119
117 120
118 120
106 121
119 121
122 123
104 123
121 124
122 124
112 125
109 126
126 127
125 127
128 129
110 129
125 130
128 130
116 131
129 131
132 133
114 133
131 134
132 134
120 135
133 135
136 137
118 137
135 138
136 138
124 139
137 139
140 141
122 141
139 142
140 142
130 143
127 144
144 145
143 145
146 147
128 147
143 148
146 148
134 149
147 149
150 151
132 151
149 152
150 152
138 153
151 153
154 155
136 155
153 156
154 156
142 157
155 157
158 159
140 159
157 160
158 160];
%Using patch() with data
patch('Faces', faces, 'Vertices', vertices)
更多回答(1 个)
Steven Lord
2023-7-7
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.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!