模块: Geom
<hr><hr>概述
<hr>注意: 直线和平面是无穷大的。
Geom模块定义了一些便于你执行不同的几何操作的方法。 这些方法将直线和平面视为arguments对象,没有用于表示他们的专门类,Array类可以用于表示两者。
直线的表示
直线可以用以下方式表示: - 一个由点组成的Array对象(表示直线通过的点)。 - 一个由点和矢量组成的Array对象(表示直线通过的点和直线的方向。)
line1 = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]line2 = [Geom::Point3d.new(0, 0, 0), Geom::Point3d.new(0, 0, 100)]
平面的表示
平面可以用以下方式表示: - 一个由点和矢量组成的Array对象(表示平面通过点和其法向量)。 - 一个由四个数值组成的Array对象,表示平面方程的四个系数。
plane1 = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]plane2 = [0, 0, 1, 0]
如果直线、平面以及矢量的知识对于你而言比较陌生,你可以参考市面上一些有关三维空间中的几何学的书籍。
软件版本:
<hr>命名空间下的定义
<hr>类:
- [[BoundingBox]]
- [[Bounds2d]]
- [[LatLon]]
- [[OrientedBounds2d]]
- [Point2d]
- [Point3d]
- [PolygonMesh]
- [Transformation]
- [Transformation2d]
- [UTM]
- [Vector2d]
- [Vector3d]
<hr>类方法目录
<hr>closest_points(line1, line2) ⇒ Array(Geom::Point3d, Geom::Point3d)
用于计算两条直线上的最近点位置。
fit_plane_to_points(args) ⇒ Object]
用于计算能够最佳适配一系列点的平面。
intersect_line_line(line1, line2) ⇒ Geom::Point3d?
用于计算两条直线的交点
intersect_line_plane(line, plane) ⇒ Geom::Point3d?
用于计算直线与平面的交点。
intersect_plane_plane(plane1, plane2) ⇒ Array(Geom::Point3d, Geom::Vector3d)
用于计算两个平面相交的结果。
linear_combination(weight1, pt_or_vect1, weight2, pt_or_vect2)
用于计算点或者矢量的线性组合。
point_in_polygon_2D(point, polygon, check_border) ⇒ Boolean
用于判定点是否在多边形内部。
tesselate(polygon_loop_points, *inner_loop_points) ⇒ Array
Tessellates a polygon, represented as a collection of 3D points.
<hr>类方法细节
<hr>closest_points(line1, line2) ⇒ [Array]
用于计算两条直线上的最近点位置。
示例代码:
line1 = [Geom::Point3d.new(0, 2, 0), Geom::Vector3d.new(1, 0, 0)]line2 = [Geom::Point3d.new(3, 0, 0), Geom::Vector3d.new(0, 1, 0)]# This will return a point Point3d(3, 2, 0).points = Geom.closest_points(line1, line2)
参数:
- line1 ([Array]) — 第一条直线
- line2 ([Array]) — 第二条直线
返回值:
- ([Array]) — 一个由两个点组成的Array对象。第一个点在第一个直线上,第二个点在第二条直线上。
软件版本:
<hr>fit_plane_to_points方法
fit_plane_to_points(point1, point2, point3, ...) ⇒ Array(Geom::Point3d, Geom::Vector3d)fit_plane_to_points**(points) ⇒ Array(Geom::Point3d, Geom::Vector3d)
用于计算能够适配一组点对现象的平面。
如果给出超过三个点,则计算出的平面可能不会通过其中一些点。
平面会以一个数组(Array)的形式返回,数组中的四个数值分别代表平面方程中的四个系数。
平面方程的形式: Ax + By + Cz + D = 0
示例代码:
point1 = Geom::Point3d.new(0, 0, 0)point2 = Geom::Point3d.new(10, 10, 10)point3 = Geom::Point3d.new(25, 25, 25)plane = Geom.fit_plane_to_points(point1, point2, point3)
重载:
fit_plane_to_points(point1, point2, point3, ...) ⇒ Array(Geom::Point3d, Geom::Vector3d)
返回一个平面.
参数:
- point1 (Geom::Point3d)
- point2 (Geom::Point3d)
- point3 (Geom::Point3d)
返回值:
- (Array)(Geom::Point3d, Geom::Vector3d)) — 表示一个平面的通过点和法向量。
fit_plane_to_points**(points) ⇒ Array(Geom::Point3d, Geom::Vector3d)
返回一个平面。
参数:
返回值:
- (Array(Geom::Point3d, Geom::Vector3d)) — 表示一个平面的通过点和法向量。
软件版本:
<hr>intersect_line_line(line1, line2) ⇒ Geom::Point3d?
<hr>用于计算两条直线的交点。
示例代码:
# Defines a line parallel to the Y axis, offset 20 units.line1 = [Geom::Point3d.new(20, 0, 0), Geom::Vector3d.new(0, 1, 0)]# Defines a line parallel to the X axis, offset 10 units.line2 = [Geom::Point3d.new(0, 10, 0), Geom::Point3d.new(20, 10, 0)]# This will return a point Point3d(20, 10, 0).point = Geom.intersect_line_line(line1, line2)
参数:
- line1 ([Array]) — 第一条直线。
- line2 ([Array]) — 第二条直线。
直线以其通过点和方向矢量的形式定义。
返回值:
- (Geom::Point3d, nil) — 相交点(如果直线不相交则返回'nil')
相关内容:
软件版本:
<hr>intersect_line_plane(line, plane) ⇒ Geom::Point3d?
<hr>用于计算直线与平面的交点。
示例代码:
# Defines a line parallel to the X axis, offset 20 units.line = [Geom::Point3d.new(-10, 20, 0), Geom::Vector3d.new(1, 0, 0)]# Defines a plane with it's normal parallel to the x axis.plane = [Geom::Point3d.new(10, 0 ,0), Geom::Vector3d.new(1, 0, 0)]# This will return a point Point3d(10, 20, 0).point = Geom.intersect_line_plane(line, plane)
参数:
- line (Array(Geom::Point3d, Geom::Vector3d))——直线
- plane (Array(Geom::Point3d, Geom::Vector3d))——平面
返回值:
- (Geom::Point3d, nil) — 一个点对象(Geom::Point3d)。(如果直线和平面不相交则返回'nil')
相关内容:
- [[Geom#直线的表示]]
- [[Geom#平面的表示]]
软件版本:
<hr>intersect_plane_plane(plane1, plane2) ⇒ Array(Geom::Point3d, Geom::Vector3d)
用于计算两个平面相交的结果。
示例代码:
# Defines a plane with it's normal parallel to the x axis.plane1 = [Geom::Point3d.new(10, 0 ,0), Geom::Vector3d.new(1, 0, 0)]# Defines a plane with it's normal parallel to the y axis.plane2 = [Geom::Point3d.new(0, 20 ,0), Geom::Vector3d.new(0, 1, 0)]# This will return a line [Point3d(10, 20, 0), Vector3d(0, 0, 1)].line = Geom.intersect_plane_plane(plane1, plane2)
参数:
- plane1 ([Array]) — 第一个平面。
- plane2 ([Array]) — 第二个平面。
返回值:
- ([Array]) — 如果成功运行则返回一条直线;如果平面之间不相交,则返回'nil'。
软件版本:
<hr>linear_combination方法
linear_combination(weight1, point1, weight2, point2) ⇒ Geom::Point3dlinear_combination(weight1, vector1, weight2, vector2) ⇒ Geom::Vector3d
用于计算两个点或者这矢量的线性结合。
线性结合是矢量计算中的一种标准方法.
矢量的线性结合=矢量1×权重1+矢量2×权重2
示例代码:
point1 = Geom::Point3d.new(1, 1, 1)point2 = Geom::Point3d.new(10, 10, 10)# Gets the point on the line segment connecting point1 and point2 that is# 3/4 the way from point1 to point2: Point3d(7.75, 7.75, 7.75).point = Geom.linear_combination(0.25, point1, 0.75, point2)
重载:
linear_combination(weight1, point1, weight2, point2) ⇒ Geom::Point3d
参数:
- weight1 (Float)
- point1 (Geom::Point3d)
- weight2 (Float)
- point2 (Geom::Point3d)
返回值:
linear_combination**(weight1, vector1, weight2, vector2) ⇒ Geom::Vector3d
参数:
- weight1 (Float)
- vector1 (Geom::Vector3d)
- weight2 (Float)
- vector2 (Geom::Vector3d)
返回值:
软件版本:
<hr>point_in_polygon_2D(point, polygon, check_border) ⇒ Boolean
<hr>用于判定点是否在给定多边形内部。
由于需要判定的点和给定多边形中的点的z坐标值会被忽略,本方法实际上是一个二维判定方法。
示例代码:
<div class="highlight"># Create a point that we want to check. (Note that the 3rd coordinate,# the z, is ignored for purposes of the check.)point = Geom::Point3d.new(5, 0, 10)# Create a series of points of a triangle we want to check against.triangle = []triangle
|