Java and MATLAB drawing polygon closed Line diagram example explanation _java

Source: Internet
Author: User



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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.