Javafx 简明教程
JavaFX - 2D Shapes(Objects) Operations
从几何学上讲,二维形状定义为可以在二维平面上显示的任何图形。如今,各种应用程序都使用此类形状来开发元素或改善其界面的外观。
Geometrically, a 2D shape is defined as any figure that can be displayed on a two-dimensional plane. Various applications these days make use of such shapes to develop an element or improve the look of their interface.
例如,考虑任何移动游戏应用程序。这些游戏在其界面上包含各种二维形状,以增强游戏的用户体验。或者,模板编辑器中使用了几个二维形状来为应用程序用户提供选项。
For example, consider any mobile game application. These games contain various 2D shapes on their interface in order to enhance the user experience of the game. Or, a template editor where several 2D shapes are used to give options to the application user.
JavaFX 提供了各种节点来创建这些二维形状,例如 Line、Circle、Rectangle、其他多边形等。然而,为了提供这些形状的排列和组合,JavaFX 还允许您对它们执行一些操作。在本节中,让我们简单了解一下所提供的操作。
JavaFX provides various nodes to create these 2D shapes like Line, Circle, Rectangle, other Polygons etc. However, to offer permutations and combinations of these shapes, JavaFX also allows you to perform some operations on them. In this chapter, let us briefly learn more about the operations provided.
JavaFX Operations on 2D Shapes
JavaFX 主要提供各种操作,用于从更简单的形状创建复杂形状。例如,我们在二维形状的前面章节中学习了如何绘制房屋。我们不得不使用几个形状,如矩形、线等,来创建最终的复杂房屋形状;通过利用这些操作,我们可以轻松地合并两个形状或从中删除一些区域。
JavaFX provides various operations mainly to create complex shapes from the simpler shapes. For instance, we learned how to draw a house in the previous chapters of 2D shapes. We had to use several shapes like rectangles, lines etc. to create the final complex house shape; by making use of these operations, we can either merge two shapes easily or remove some area from it.
JavaFX 中有三种操作可对二维形状执行。它们如下所示:
There are three operations available in JavaFX that can be performed on 2D shapes. They are listed below −
通常,二维形状具有它们在应用程序中覆盖的特定区域。这三种操作通过将区域相加或从另一个形状中减去形状区域等,对这些形状所覆盖的区域执行。
Usually, 2D shapes have a certain area they cover in an application. These three operations are performed on the area covered by these shapes by adding the area together, or subtracting a shape area from another shape, etc.
Union Operation
联合操作通常定义为应用程序中两个或更多元素的组合。在 JavaFX 中,联合操作可以在二维形状上执行,其中两个或多个形状被视为输入,并将它们的区域组合在一起。此操作基本上以以下韦恩图的形式表示:
Union Operation is generally defined as the combination of two or more elements in an application. In JavaFX, a union operation can be performed on 2D shapes where two or more shapes are taken as inputs and combines the area of them together. This operation is fundamentally represented in the form of a following venn diagram −
Intersection Operation
交集操作保留两个或更多集合中的公共元素。当与 JavaFX 中的二维形状一起使用时,将保留两个或多个形状的公共区域。这也称为对象的交集区域。查看下面显示的图像以更好地理解。
Intersection operation retains the common elements from two or more sets. When used with 2D shapes in JavaFX, the common area of two or more shapes will be retained. This is also known as the intersected area of the objects. Look at the image shown below for better understanding.
Subtraction Operation
减法操作,也称为差分操作,从一个集合中减去另一个集合的元素。如果某些元素不存在于第一个集合中(另一个集合从中减去的集合),则会忽略这些元素。在 JavaFX 中,只要二维形状相交,一个二维形状的区域就会从另一个二维形状的区域中减去。
Subtraction Operation, also known as the Difference Operation, subtracts the elements of one set from another set. If some elements are not present in the first set (the set from which another set is being subtracted), they are ignored. In JavaFX, an area of a 2D shape is subtracted from the area of another 2D shape as long as they intersect.