Common features of geometric frameworks in Java class libraries
In the Java class library, the geometric framework provides many common functions to process and operate geometric graphic objects.These functions allow developers to easily perform geometric and graphic operations.Here are some common functions in the geometric framework and its corresponding Java code example:
1. Point operation:
-Colon a point object: Use the constructor of the Point class to create a point object.
Point p = new Point(10, 20);
-Cela to get points: Use the getX () and Gety () methods to obtain the coordinates of the point object.
int x = p.getX();
int y = p.getY();
-Set the coordinates of the point: Use the setlocation () method to set the coordinates of the point object.
p.setLocation(30, 40);
2. Line operation:
-Coloning a line object: Use the constructor of the LINE class to create a line object.
Line l = new Line(new Point(10, 20), new Point(30, 40));
-Cap the starting point and end of the line: Use GetStartpoint () and Getendpoint () methods to obtain the starting point and end of the line object.
Point startPoint = l.getStartPoint();
Point endPoint = l.getEndPoint();
-Accut the length of the line: The length of the line object can be calculated using the Linelength () method.
double length = l.lineLength();
3. Rectangle operation:
-Colid a rectangular object: Use the constructor of the RECTANGLE class to create a rectangular object.
Rectangle r = new Rectangle(10, 20, 30, 40);
-Cap the position and size of the rectangle: use Getx (), Gety (), GetWidth (), and Getheight () methods to obtain the position and size of the rectangular object.
int x = r.getX();
int y = r.getY();
int width = r.getWidth();
int height = r.getHeight();
-The judgment point is in the rectangular: use the contains () method to determine whether a point is in the rectangle.
boolean containsPoint = r.contains(new Point(5, 5));
4. Circle operation:
-Coloning a circular object: The constructor using the Circle class can create a circular object.
Circle c = new Circle(new Point(10, 20), 30);
-Caping heart and radius: Use the getcenter () and getradius () methods to obtain the circular heart and radius of the circular object.
Point center = c.getCenter();
double radius = c.getRadius();
-The judgment point is in the circle: Use the contains () method to determine whether a point is in a circle.
boolean containsPoint = c.contains(new Point(15, 25));
5. Polygon operation:
-Coloning a polygon object: The constructor using the Polygon class can create a polygon object.A series of dot objects can be passed to represent the vertices of the polygon.
Polygon polygon = new Polygon(new Point(10, 20), new Point(30, 40), new Point(50, 60));
-Cap the number of polygon vertices and coordinates of each vertex: Use GetVertexcount () and GetVertex () methods to obtain the number of vertices of the polygon object and coordinates of each vertex.
int vertexCount = polygon.getVertexCount();
Point vertex = polygon.getVertex(0);
-The judgment point is in polygon: Use the contains () method to determine whether a point is in the polygon.
boolean containsPoint = polygon.contains(new Point(15, 25));
The above is some common functions and corresponding Java code examples of the geometric framework in the Java library.Developers can process and operate geometric graphic objects based on these functions.