1. Use matlab to make closed polygon diagrams
There is no function to directly draw polygons. The only way is to save the coordinates of each point in an array, connect one point to its adjacent points, and connect the last point to the first point. Here is an example .m file:
Copy the code code as follows:
clear;
clc;
a=[0 2 4 6 8 10 12 14;0 2 1 4 6 6 5 7]; %Coordinates of the points to be connected x;y
[n,m]=size(a);
for i=1:m-1;
line([a(1,i),a(1,i+1)],[a(2,i),a(2,i+1)]); % connect the nodes line([x1,x2], [y1,y2])
hold on
end
hold on
line([a(1,1),a(1,m)],[a(2,1),a(2,m)]); %The first and last nodes are connected
2. Use Java to make closed polygon diagrams
The drawPolygon function of the Graphics class in Java provides direct polygon drawing.
Function prototype: public abstract void drawPolygon(int[] xPoints, int[] yPoints,int nPoints)
illustrate
(1) Draw a closed polygon defined by x and y coordinate arrays. Each pair of (x, y) coordinates defines a point. nPoints represents the number of line segments.
(2) The previous nPoint - 1 line segment is the line segment from (xPoints[i-1], yPoints[i-1]) to (xPoints[i], yPoints[i]) when 1 ≤ i ≤ nPoints. If the last point is different from the first point, the shape is automatically closed by drawing a line segment between the two points.
The code example is as follows:
Copy the code code as follows:
import java.applet.*;
import java.awt.*;
public class DrawPicture extends Applet
{ public void paint(Graphics g)
{
int px[]={20,70,130,240};
int py[]={20,150,100,130};
g.drawPolygon(px,py,4);
}
}
3.Description
Whether a polygon, a convex polygon, or a concave polygon can be formed depends on the order of the given points.
The program is only responsible for connecting adjacent nodes and connecting them head to tail.