本文翻译自Oracle官方教程
<<Previous • Trail • Next>>
几何图元
The Java 2D API provides a useful set of standard shapes such as points, lines, rectangles, arcs, ellipses, and curves.
Java 2D API 提供了一套有用的标准图形,如点、直线、矩形、弧、椭圆和曲线。
The most important package to define common geometric primitives is the java.awt.geom package.
用来定义公共几何图元的最重要的包就是java.awt.geom。
Arbitrary shapes can be represented by combinations of straight geometric primitives.
不规则图形可以用整齐的几何图元的组合来表示。
The Shape interface represents a geometric shape, which has an outline and an interior.
Shape接口代表一个有轮廓和内部的几何图形。
This interface provides a common set of methods for describing and inspecting two-dimensional geometric objects and supports curved line segments and multiple sub-shapes.
为了描述和检查二维几何对象,并且支持曲线段和多种子图形,这个接口提供了一组公共方法。
The Graphics class supports only straight line segments. The Shape interface can support curves segments.
Graphics类只支持直线段。Shape接口可以支持曲线段。
For more details about how to draw and fill shapes, see the Working with Geometry lesson.
关于如何绘制和填充图形的更多细节,参见 几何运作 课程。
点
The Point2D class defines a point representing a location in (x, y) coordinate space.
Point2D类定义了在(x, y)坐标空间中代表一个位置的点。
The term “point” in the Java 2D API is not the same as a pixel. A point has no area, does not contain a color, and cannot be rendered.
在Java 2D API中”点“和"像素"不是一个概念。点是没有区域和颜色的,无法被渲染。
Points are used to create other shapes. The Point2D class also includes a method for calculating the distance between two points.
点是用来创造其他图形的。Point2D类还包含了一个方法来计算两点之间的距离。
直线
The Line2D class is an abstract class that represents a line.
不过Line2D类的源码注释里写的是:This Line2D represents a line segment in (x,y)coordinate space.
而且下面紧接着提到设置line的端点,所以这里的line应该指的是直线段。
这篇教程涉及到线和线段的地方有些含糊,有的地方所讲的和图片展示的都是线段“line segment”,但句子当中的用词却是线“line”。
Line2D类是个抽象类,代表一条直线段。
A line’s coordinates can be retrieved as double.
直线段(端点的)坐标可以是双精度的。
The Line2D class includes several methods for setting a line’s endpoints.
Line2D类包括了一些方法来设置直线段的端点。
You can also create a straight line segment by using the GeneralPath class described below.
你也可以用下面所述的GeneralPath类创建一条直线段。
类矩形
The Rectangle2D, RoundRectangle2D, Arc2D, and Ellipse2D primitives are all derived from the RectangularShape class.
Rectangle2D、RoundRectangle2D、Arc2D、Ellipse2D,这些图元都是由RectangularShape类衍生出来的。
This class defines methods for Shape objects that can be described by a rectangular bounding box.
图形对象当中有一些是可以用矩形边框来描述的,而RectangularShape类中的方法就是为它们定义的。
The geometry of a RectangularShape object can be extrapolated from a rectangle that completely encloses the outline of the Shape.
一个RectangularShape对象的几何结构可以由一个完全包围住它的矩形推出来。
二次和三次曲线
The QuadCurve2D enables you to create quadratic parametric curve segments. A quadratic curve is defined by two endpoints and one control point.
QuadCurve2D类使你能够创建二次参数曲线段。二次曲线段由两个端点和一个控制点定义。
The CubicCurve2D class enables you to create cubic parametric curve segments. A cubic curve is defined by two endpoints and two control points.
CubicCurve2D类使你能够创建三次参数曲线段。三次曲线段由两个端点和两个控制点定义。
The following are examples of quadratic and cubic curves. See Stroking and Filling Graphics Primitives for implementations of cubic and quadratic curves.
下面是二次和三次曲线的例子,它们的具体实现可以参考 描边和填充图元。
This figure represents a quadratic curve.
此图描述了一条二次曲线段。
This figure represents a cubic curve.
此图描述了一条三次曲线段。
不规则图形
The GeneralPath class enables you to construct an arbitrary shape by specifying a series of positions along the shape’s boundary.
通过沿着图形边界指定一连串位置的方式,GeneralPath类使你能够构造出不规则图形。
These positions can be connected by line segments, quadratic curves, or cubic (Bézier) curves.
这些位置可以用直线段,二次曲线段或三次(贝塞尔)曲线段链接起来。
The following shape can be created with three line segments and a cubic curve. See Stroking and Filling Graphics Primitives for more information about the implementation of this shape.
下面的图形可以用三条直线段和一条曲线段来构造。关于构造的过程,想要了解更多可以参考 描边和填充图元。
区域
With the Area class, you can perform boolean operations, such as union, intersection, and subtraction, on any two Shape objects.
有了Area类,你就可以对任意两个图形对象执行布尔运算,比如取并集、取交集、取差集。
This technique, often referred to as constructive area geometry, enables you to quickly create complex Shape objects without having to describe each line segment or curve.
这项技术(通常被称为 构造性区域几何)使你不必去描述每条线段即可快速的创建出复杂图形对象。
<<Previous • Trail • Next>>