1. Use Matlab as a closed polygon drawing
Instead of finding a function that directly draws a polygon, you can only save the coordinates of each point in an array, connect a point to its adjacent point, and attach the last point to the first point. The following is an example of the. m File:
Copy Code code as follows:
Clear
CLC
A=[0 2 4 6 8 10 12 14;0 2 1 4 6 6 5 7]; % the point coordinates 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)]); % connection node line ([X1,x2],[y1,y2])
Hold on
End
Hold on
Line ([A (1,1), A (1,m)],[a (2,1), A (2,m)]); % end-to-end node connected
2. Using Java as a closed polygon drawing
The Graphics class DrawPolygon function in Java provides a direct polygon drawing.
Function prototypes: Public abstract void DrawPolygon (int[] xpoints, int[] ypoints,int npoints)
Description
(1) Draw a closed polygon defined by an array of x and Y coordinates. Each pair (x, y) coordinates defines a point. Npoints represents the number of segments.
(2) The line segment in front of the nPoint-1 is when 1≤i≤npoints, from (Xpoints[i-1], ypoints[i-1]) to (Xpoints[i], ypoints[i]). If the last point is different from the first, the graph is automatically closed by drawing a line segment between the two points.
The code example is as follows:
Copy 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. Notes
Whether it can form polygons, convex polygons, or concave polygons, which are related to the order of the given points.
The program is only responsible for connecting the adjacent nodes, as well as the End-to-end connection.