概述


SketchUp Array类为[[标准Ruby Array]]添加了一些额外的方法。

另外它还包含了一些允许一个Array执行类似[[Geom]]类的[[Vector3d]]子类或者[[Point3d]]子类对象的方法(事实上这些对象可以某种程度上看作其三维坐标值作为内容的array)。

因此你可以在传递三维坐标值时使用[[Array]]类来代替上面这两个类。


实例代码


  1. # 下面定义的这个array代表了一个z坐标为1单位的vector(矢量)对象
  2. array = [0, 0, 1]
  3. # 同样的array也可以代表z坐标为1单位的point(点)对象
  4. array = [0, 0, 1]
  5. # 它会被怎样诠释取决于上下文代码. 例如,这段代码创建了一个位于0,0,1位置的点对象,因为上下文中出现了point.
  6. entities = Sketchup.active_model.entities
  7. construction_point = entities.add_cpoint(array)
  8. # 而下面这段代码会将这个点向z轴正方向移动1单位,因为上下文中出现了vector
  9. transformation = Geom::Transformation.new(array)
  10. entities.transform_entities(transformation, construction_point)

生效版本

SketchUp 6.0


实例方法目录


cross(vector) ⇒ Object

用于计算两个矢量的交点。

distance(point) ⇒ Object

用于计算两个点之间的距离

distance_to_line(*args) ⇒ Object

用于计算点与直线之间的距离。

distance_to_plane(*args) ⇒ Object

用于计算点与平面之间的距离。

dot(vector) ⇒ Object

用于计算两个矢量的点积(数量积)。

normalize ⇒ Object

用于将矢量单位化。

normalize! ⇒ Object

用于将矢量在原位置单位化。

offset(*args) ⇒ Object

用于将点偏移给定矢量值。

offset!(*args) ⇒ Object

用于将点偏移给定矢量值。

on_line?(*args) ⇒ Object

用于判定点是否在给定直线上。

on_plane?(*args) ⇒ Boolean

用于判定点是否在给定平面上(在Sketchup的默认点坐标精度内)。

project_to_line(*args) ⇒ Object

用于获取点在给定直线上的投影点位置。

project_to_plane(*args) ⇒ Object

用于获取点在给定平面上的投影点位置。

transform(transform) ⇒ Object

用于将一个Geom::Transformation或者Geom::Transformation2d对象应用到对象上。

并返回一个新的对象。

transform!(transform) ⇒ Object

用于将一个Geom::Transformation或者Geom::Transformation2d对象应用到对象上。

并改变原始对象的坐标值并返回。

vector_to(point) ⇒ Object

用于创建一个代表点到另一个点的矢量的Array对象。

x ⇒ Object?

用于获取x坐标值。

x=(x) ⇒ Object

用于设定x坐标值。

y ⇒ Object?

用于获取y坐标值。

y=(y) ⇒ Object

用于设定y坐标值。

z ⇒ Object?

用于获取z坐标值。

z=(z) ⇒ Object

用于设定z坐标值。


实例方法细节


cross(vector)方法

  1. cross(vector) Geom::Vector3d
  2. cross(vector) Geom::Vector2d

功能

[[cross]]方法用于计算两个矢量的交点

示例代码

对于三维数组([[Array]])对象

  1. vector1 = Geom::Vector3d.new(0, 1, 0)
  2. array = [1, 0, 0]
  3. # 下面的代码返回一个新的三维数组
  4. # 这个数组的内容表示array所代表矢量与vector1的交点
  5. vector2 = array.cross(vector1)

对于二维数组([[Array]])对象,当计算其与二维数组的交点时返回值为二维数组,当计算其与三维数组的交点时返回值为三维数组

  1. vector1 = Geom::Vector2d.new(0, 1)
  2. array = [1, 0]
  3. vector2 = array.cross(vector1)
  4. vector1 = Geom::Vector3d.new(0, 1, 0)
  5. array = [1, 0]
  6. vector2 = array.cross(vector1) # 此时返回值为[1,0,0]

重载

cross(vector) ⇒ Geom::Vector3d

参数:
vector (Geom::Vector3d)

返回值:
(Geom::Vector3d)

cross(vector) ⇒ Geom::Vector2d

参数:

vector (Geom::Vector2d)

返回值:

(Geom::Vector2d)

异常

  • ArgumentError:如果传入的矢量类型错误会产生ArgumentError

软件版本

  • [[SketchUp 6.0]]以后生效

distance(point)方法

  1. distance(point) Length
  2. distance(point) Length

功能

distance方法用于计算两个点之间的距离

示例代码

对于三维数组([[Array]])对象

  1. point = Geom::Point3d.new(10, 10, 10)
  2. array = [1, 1, 1]
  3. # This will return a Length
  4. distance = array.distance(point)

对于二维数组([[Array]])对象,当计算其与二维数组的距离时返回值为二维数组,当计算其与三维数组的距离时返回值为三维数组

  1. point = Geom::Point2d.new(10, 10)
  2. array = [1, 2]
  3. distance = array.distance(point)
  4. point = Geom::Point3d.new(10, 10, 10)
  5. distance = array.distance(point)

重载

distance(point) ⇒ Length

参数:

  • point (Geom::Point3d)

返回值:

  • (Length)

distance(point) ⇒ Length

参数:

  • point (Geom::Point3d)

返回值:

  • (Length)

异常

  • ArgumentError:如果传入的点类型错误会产生ArgumentError

软件版本

  • [[SketchUp 6.0]]以后生效

distance_to_line方法

  1. distance_to_line(point, vector) Length
  2. distance_to_line(point1, point2) Length

用于计算点(Geom::Vector3d)到给定直线之间的距离。

示例代码:

  1. line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
  2. array = [10, 10, 10]
  3. # This will return a Length
  4. distance = array.distance_to_line(line)

重载:

distance_to_line(point, vector) ⇒ Length

参数:

point (Geom::Point3d)

vector (Geom::Vector3d)

返回值:

(Length)

distance_to_line(point1, point2) ⇒ Length

参数:
  • point1 (Geom::Point3d)
  • point1 (Geom::Point3d)

返回值:

(Length)

相关内容:
  • [[../Geom/Geom#|Geom模块中有关如何创建一条直线的指令。]]

软件版本:
  • SketchUp 6.0

distance_to_plane方法

  1. distance_to_plane(point, vector) Length
  2. distance_to_plane(point1, point2, point3) Length
  3. distance_to_plane(float1, float2, float3, float4) Length
  4. distance_to_plane(array) Length
  5. distance_to_plane(array) Length
  6. distance_to_plane(array) Length

用于计算点到给定平面的距离。

示例代码:

  1. plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
  2. array = [10, 10, 10]
  3. # This will return a Length
  4. distance = array.distance_to_plane(plane)

重载:

distance_to_plane(point, vector) ⇒ Length

给定平面由以下参数定义。

参数:
  • point (Geom::Point3d)
  • vector (Geom::Vector3d)

返回值:
  • (Length) — 点到给定平面的距离。

distance_to_plane(point1, point2, point3) ⇒ Length

注意:三个点不能共线或者重复。

平面由以下参数给定的三个点定义

参数:
  • point1 (Geom::Point3d)
  • point2 (Geom::Point3d)
  • point3 (Geom::Point3d)

返回值:
  • (Length) — 点到由三个点参数所确定的平面之间的距离。

distance_to_plane(float1, float2, float3, float4) ⇒ Length

平面由以下四个浮点数参数确定。
它们代表平面方程中各项的系数。

参数:
  • float1 (Float)
  • float2 (Float)
  • float3 (Float)
  • float4 (Float)

返回值:
  • (Length) — 返回点到由四个系数所确定的平面之间的距离。

distance_to_plane(array) ⇒ Length

注意: 三点不能共线或者重复。

平面由一个Array对象确定,其两个成员分别代表了平面的通过点和其法向量。

参数:

返回值:
  • (Length) — 点到给定平面之间的距离。

distance_to_plane(array) ⇒ Length

平面由一个Array对象定义,其三个成员分别代表了平面上的三个点。

参数:
  • point (Array)

返回值:
  • (Length) — 点到给定平面的距离

distance_to_plane(array) ⇒ Length

平面由一个Array对象确定,其四个成员(浮点数)分别代表了平面方程中四个项的系数。

参数:
  • point (Array)

返回值:
  • (Length) — 点到给定平面的距离。

相关内容

软件版本:

  • SketchUp 6.0

dot(vector)方法

  1. dot(vector) Float
  2. dot(vector) Float

用于计算两个向量之间的点积(数量积)。

示例代码:

With 3d array

  1. vector = Geom::Vector3d.new(12, 12, 0)
  2. array = [12, 0, 0]
  3. # This will return a Float, in this case 144.0
  4. dot_product = array.dot(vector)

With 2d array

  1. vector = Geom::Vector2d.new(12, 12)
  2. array = [12, 0]
  3. # This will return a float
  4. dot_product = array.dot(vector)

重载:

dot(vector) ⇒ Float

参数:
  • vector (Geom::Vector3d)

返回值:
  • (Float)——代表连个矢量的点积。

dot(vector) ⇒ Float

参数:
  • vector (Geom::Vector2d)

返回值:
  • (Float)——表示两个矢量的点积。

异常:

  • 当传入的矢量类型错误时会抛出ArgumentError。

软件版本:

  • SketchUp 6.0

normalize方法

normalize ⇒ Array(Float, Float, Float)
normalize ⇒ Array(Float, Float)

注意:传入的参数和返回值都会被转化为浮点数,注意与Geom::Vector3d#normalize!方法行为的不同之处

用于将矢量单位化(将矢量长度变为1单位)。
这个方法会传回一个新的矢量,而不是改变原始矢量的值。

示例代码:

With 3d array

  1. array = [1, 2, 3]
  2. # This will return a new Vector3d
  3. normal_vector = array.normalize

With 2d array

  1. array = [1, 2]
  2. normal_vector = array.normalize

重载:

normalize ⇒ Array(Float, Float, Float)

返回一个代表原始矢量单位化之后结果的新Array对象

返回值:
  • (Array(Float, Float, Float)) — 代表原始矢量单位化之后结果的Array对象。

normalize ⇒ Array(Float, Float)

返回一个代表原始矢量单位化之后结果的新Array对象

返回值:
  • (Array(Float, Float)) — 代表原始矢量单位化之后结果的新Array对象

软件版本:

  • SketchUp 6.0

normalize!方法

normalize! ⇒ Array(Float, Float, Float)
normalize! ⇒ Array(Float, Float)

用于将矢量就地矢量化。
这代表着这个方法会改变原始矢量的值。

示例代码:

With 3d array

  1. array = [1, 2, 3]
  2. # This will modify 'array' in place
  3. array.normalize!

With 2d array

  1. array = [1, 2]
  2. array.normalize!

重载:

normalize! ⇒ Array(Float, Float, Float)

将原始矢量的值改为长度为单位长度且方向不变的新值,并返回值被改变之后的原始矢量
返回值:

  • (Array(Float, Float, Float)) ——表示值被改变之后的原始矢量

normalize! ⇒ Array(Float, Float)

将原始矢量的值改为长度为单位长度且方向不变的新值,并返回值被改变之后的原始矢量

返回值:
  • (Array(Float, Float)) — 代表值被改变之后的原始矢量

软件版本:

  • SketchUp 6.0

offset方法

  1. offset(vector) Array(Length, Length, Length)
  2. offset(vector) Array(Length, Length)
  3. offset(vector, length) Array(Length, Length, Length)
  4. offset(vector, length) Array(Length, Length)

offset方法用于计算点按照给定矢量值偏移之后的结果。
本方法不会改变给定点的原始值,而是将偏移之后的结果以新的Array对象的形式给出。

示例代码:

With 3d array

  1. array = [10, 10, 10]
  2. vector = Geom::Vector3d.new(0, 0, 1)
  3. # This will modify 'array' in place
  4. length_array = array.offset(vector)

With 2d array

  1. array = [10, 10]
  2. vector = Geom::Vector2d.new(0, 1)
  3. length_array = array.offset(vector)
  4. # Using Vector3d with a 2d array
  5. array = [10, 10]
  6. vector = Geom::Vector3d.new(0, 0, 1)
  7. length_array = array.offset(vector)

重载:

offset(vector) ⇒ Array(Length, Length, Length)

返回代表偏移之后值(点或者矢量)的新Array对象

参数:
  • vector (Geom::Vector3d) — 代表用于偏移的矢量值。

返回值:
  • (Array(Length, Length, Length)) — 代表偏移之后值(点或者矢量)的新Array对象

offset(vector) ⇒ Array(Length, Length)

返回代表偏移之后值(点或者矢量)的新Array对象。

参数:
  • vector (Geom::Vector2d) — 代表用于偏移的矢量值。

返回值:
  • (Array(Length, Length)) — 代表偏移之后值(点或者矢量)的新Array对象。

offset(vector, length) ⇒ Array(Length, Length, Length)

返回代表偏移之后值(点或者矢量)的新Array对象。

参数:
  • vector (Geom::Vector3d) — 用于表示偏移方向的矢量。
  • length (Length) — 用于表示偏移距离值,这个参数将会覆盖上面的矢量参数的长度。

返回值:
  • (Array(Length, Length, Length)) — 代表偏移之后值(点或者矢量)的新Array对象。

offset(vector, length) ⇒ Array(Length, Length)

返回代表偏移之后值(点或者矢量)的新Array对象。

参数:
  • vector (Geom::Vector2d) — 用于表示偏移方向的二维矢量。
  • length (Length) — 用于表示偏移距离值,这个参数将会覆盖上面的矢量参数的长度。

返回值:
  • (Array(Length, Length)) — 返回代表偏移之后值(点或者矢量)的新Array对象。

异常 :

  • 矢量类型错误时抛出ArgumentError

软件版本:

  • SketchUp 6.0

offset!方法

  1. offset!(vector) Array(Length, Length, Length)
  2. offset!(vector) Array(Length, Length)
  3. offset!(vector, length) Array(Length, Length, Length)
  4. offset!(vector, length) Array(Length, Length)

注意:本方法改变原始对象。

用于以给定矢量值偏移原始点。
本方法会直接改变原始对象的坐标值。

示例代码:

With 3d array

  1. array = [10, 10, 10]
  2. vector = Geom::Vector3d.new(0, 0, 1)
  3. # This will modify 'array' in place
  4. array.offset!(vector)

With 2d array

  1. array = [10, 10]
  2. vector = Geom::Vector2d.new(0, 1)
  3. array.offset!(vector)
  4. # Using Vector3d with a 2d array
  5. array = [10, 10]
  6. vector = Geom::Vector3d.new(0, 0, 1)
  7. array.offset!(vector)

重载:

offset!(vector) ⇒ Array(Length, Length, Length)

返回原始点改变坐标之后的结果。

参数:
  • vector (Geom::Vector3d) — 偏移矢量值。

返回值:
  • (Array(Length, Length, Length)) — 原始点改变坐标之后的结果。

offset!(vector) ⇒ Array(Length, Length)

返回原始点改变坐标之后的结果。

参数:
  • vector (Geom::Vector2d) — 偏移矢量值

返回值:
  • (Array(Length, Length)) — 原始点改变坐标之后的结果。

offset!(vector, length) ⇒ Array(Length, Length, Length)

返回原始点改变坐标之后的结果。

参数:
  • vector (Geom::Vector3d) — 表示偏移方向的矢量值。
    A Vector3d object used to offset the point.
  • length (Length) — 用于表示偏移距离值,这个参数将会覆盖上面的矢量参数的长度。

返回值:
  • (Array(Length, Length, Length)) —

返回原始点改变坐标之后的结果。

offset!(vector, length) ⇒ Array(Length, Length)

返回原始点改变坐标之后的结果。

参数:

  • vector (Geom::Vector2d) — 表示偏移方向的矢量值。
  • length (Length) — 用于表示偏移距离值,这个参数将会覆盖上面的矢量参数的长度。

返回值:
  • (Array(Length, Length)) — 返回原始点改变坐标之后的结果。

异常:

  • 如果矢量类型错误则抛出ArgumentError。

软件版本:

  • SketchUp 6.0

on_line?方法

  1. on\_line?(point, vector) Boolean
  2. on\_line?(point1, point2) Boolean

用于判定一个三维点(Geom::Point3d)对象是否位于给定直线上。

示例代码:

  1. line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
  2. array = [10, 10, 10]
  3. # This will return a true or false value
  4. on_plane = array.on_line?(line)

重载:

on_line?(point, vector) ⇒ Boolean

如果点在直线上返回true,否则返回false。

参数:
  • point (Geom::Point3d)
  • vector (Geom::Vector3d)

返回值:
  • (Boolean) — 如果点在直线上返回true,否则返回false。

on_line?(point1, point2) ⇒ Boolean

如果点在直线上返回true,否则返回false。

参数:
  • point1 (Geom::Point3d)
  • point1 (Geom::Point3d)

返回值:
  • (Boolean) — 如果点在直线上返回true,否则返回false。

相关内容:

  • The Geom module for instructions on how to create a line.

软件版本:

  • SketchUp 6.0

on_plane?方法

  1. on\_plane?(point, vector) Boolean
  2. on\_plane?(point1, point2, point3) Boolean
  3. on\_plane?(float1, float2, float3, float4) Boolean
  4. on\_plane?(array) Boolean
  5. on\_plane?(array) Boolean
  6. on\_plane?(array) Boolean

用于判定一个三维点(Geom::Point3d)对象是否在给定平面上。(在Sketchup默认的浮点值公差范围内。)

示例代码:

  1. plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
  2. array = [10, 10, 10]
  3. # This will return a true or false value
  4. on_plane = array.on_plane?(plane)

重载:

on_plane?(point, vector) ⇒ Boolean

平面以通过点和法向量定义。

参数:
  • point (Geom::Point3d)——平面通过点。
  • vector (Geom::Vector3d)——平面的法向量。

on_plane?(point1, point2, point3) ⇒ Boolean

注意:三点不能共线或重复。

平面以三个通过点确定。

参数:
  • point1 (Geom::Point3d)
  • point2 (Geom::Point3d)
  • point3 (Geom::Point3d)
    以上参数给出平面通过的三个点。

on_plane?(float1, float2, float3, float4) ⇒ Boolean

平面以其方程的各项系数确定。

参数:
  • float1 (Float)
  • float2 (Float)
  • float3 (Float)
  • float4 (Float)
    以上参数表示平面方程中各项的系数。

on_plane?(array) ⇒ Boolean
  1. >注意:三点不能共线或者重复。

平面以Array对象的形式定义,其两个成员分别代表平面通过点及其法向量。

参数:
  • point (Array)

on_plane?(array) ⇒ Boolean

平面以Array对象的形式定义,三个成员分别代表平面通过的三个点。

参数:
  • point (Array)

on_plane?(array) ⇒ Boolean

平面以Array对象的形式定义,四个成员分别代表平面方程的各项系数。

参数:
  • point (Array)

返回值:

  • (Boolean)

相关内容:

软件版本:

  • SketchUp 6.0

project_to_line方法

project_to_line(point, vector) ⇒ Array(Length, Length, Length)
project_to_line(point1, point2) ⇒ Array(Length, Length, Length)

用于获取点在给定直线上的投影位置。

示例代码:

  1. line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
  2. array = [10, 10, 10]
  3. # This will return a new Array
  4. point_on_line = array.project_to_line(line)

重载:

project_to_line**(point, vector) ⇒ Array(Length, Length, Length)

返回代表投影位置的新点对象。

参数:
  • point (Geom::Point3d)——表示直线通过点。
  • vector (Geom::Vector3d)——表示直线方向。

返回值:
  • (Array(Length, Length, Length)) — 新的点对象,代表点在给定直线上的投影。(也就是直线上离已知点最近的点。)

project_to_line**(point1, point2) ⇒ Array(Length, Length, Length)

返回代表投影位置的新点对象。

参数:
  • point1 (Geom::Point3d)
  • point1 (Geom::Point3d)
    表示直线通过的两个点。

返回值:
  • (Array(Length, Length, Length)) — 新的点对象,代表点在给定直线上的投影。(也就是直线上离已知点最近的点。)

相关内容:

  • [The Geom module for instructions on how to create a line.]

软件版本:

  • SketchUp 6.0

project_to_plane方法

  1. project_to_plane(point, vector) Array(Length, Length, Length)
  2. project_to_plane(point1, point2, point3) Array(Length, Length, Length)
  3. project_to_plane(float1, float2, float3, float4) Array(Length, Length, Length)
  4. project_to_plane(array) Array(Length, Length, Length)
  5. project_to_plane(array) Array(Length, Length, Length)
  6. project_to_plane(array) Array(Length, Length, Length)

用于获取已知点在给定平面上的投影位置。

示例代码:

  1. plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
  2. array = [10, 10, 10]
  3. point_on_plane = array.project_to_plane(plane)

重载:

project_to_plane(point, vector) ⇒ Array(Length, Length, Length)

平面以通过点和法向量的形式定义。

参数:
  • point (Geom::Point3d)——平面的通过点。
  • vector (Geom::Vector3d)——平面的法向量。

返回值:
  • (Array(Length, Length, Length))

project_to_plane(point1, point2, point3) ⇒ Array(Length, Length, Length)

注意:三点不能共线或者重复。

平面以三个通过点定义。
Plane defined by three points.

参数:
  • point1 (Geom::Point3d)
  • point2 (Geom::Point3d)
  • point3 (Geom::Point3d)

返回值:
  • (Array(Length, Length, Length))

project_to_plane(float1, float2, float3, float4) ⇒ Array(Length, Length, Length)

平面以其方程各项系数定义。

参数:
  • float1 (Float)
  • float2 (Float)
  • float3 (Float)
  • float4 (Float)

返回值:
  • (Array(Length, Length, Length))

project_to_plane(array) ⇒ Array(Length, Length, Length)

注意:三点不能共线或者重复。

平面以其通过点和法向量组成的Array定义。

参数:
  • point (Array(Geom::Point3d, Geom::Vector3d))

返回值:

  • (Array(Length, Length, Length))

project_to_plane(array) ⇒ Array(Length, Length, Length)

平面以三个通过点组成的Array定义

参数:
  • point (Array(Geom::Point3d, Geom::Point3d, Geom::Point3d))

返回值:
  • (Array(Length, Length, Length))

project_to_plane(array) ⇒ Array(Length, Length, Length)

平面以其方程的各项系数组成的Array定义。

参数:
  • point (Array(Float, Float, Float, Float))

返回值:
  • (Array(Length, Length, Length))

相关内容:

软件版本:

  • SketchUp 6.0

transform方法

  1. transform(transform) Array<Length, Length>
  2. transform(transform) Array<Length, Length, Length>

用于将一个Geom::Transformation或者Geom::Transformation2d对象应用到一个Geom::Point3d或者Geom::Point2d对象上。

本方法返回一个新的Array对象而不是改变原始对象。

示例代码:

point1 = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point1)
array = [1, 2, 3]
# This will return a new Array
point2 = array.transform(transform)

重载:

transform(transform) ⇒ Array

返回在原始点变换后的新位置的新点对象

参数:
  • transform (Geom::Transformation2d)

返回值:
  • (Array) —

变换后的新点对象

transform(transform) ⇒ Array

返回在原始点变换后的新位置的新点对象

参数:
  • transform (Geom::Transformation)

返回值:
  • (Array) —

在原始点变换后的新位置的新点对象

软件版本:

  • SketchUp 6.0

transform!方法

transform!(transform) ⇒ Array
transform!(transform) ⇒ Array

注意:本方法改变原始对象。

用于将一个Geom::Transformation或者Geom::Transformation2d对象应用到一个Geom::Point3d或者Geom::Point2d对象上。

本方法改变原始对象。

示例代码:

point = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point)
array = [1, 2, 3]
# This will modify 'array' in place
array.transform!(transform)

重载:

transform!(transform) ⇒ Array

将原始对象的坐标值改为变换后的坐标值。

参数:
  • transform (Geom::Transformation2d)

返回值:
  • (Array) — 坐标值改变之后的点对象。

transform!(transform) ⇒ Array

将原始对象的坐标值改为变换后的坐标值并返回。

参数:
  • transform (Geom::Transformation)

返回值:
  • (Array) — 标值改变之后的点对象。

软件版本:

  • SketchUp 6.0

vector_to方法

vector_to(point) ⇒ Geom::Vector3d
vector_to(point) ⇒ Geom::Vector2d

用于创建一个从已知点到给定的第二个点的矢量。

示例代码:

With 3d array

point = Geom::Point3d.new(10, 20, 30)
array = [1, 2, 3]
# This will return a new Vector3d
vector = array.vector_to(point)

With 2d array

point = Geom::Point2d.new(10, 20)
array = [1, 2]
# This will return a new Vector2d
vector = array.vector_to(point)

point = Geom::Point3d.new(10, 20)
# This will return a new Vector3d
vector = array.vector_to(point)

重载:

vector_to(point) ⇒ Geom::Vector3d

参数:
  • point (Geom::Point3d)

返回值:
  • (Geom::Vector3d)

vector_to(point) ⇒ Geom::Vector2d

参数:
  • point (Geom::Point2d)

返回值:
  • (Geom::Vector2d)

异常:

  • 如果点类型错误则抛出ArgumentError 。

软件版本:

  • SketchUp 6.0

x方法

x ⇒ Object?

用于提取对象的x值

示例代码:

array = [1, 2, 3]
# This will return a Fixnum, in this case 1
x = array.x

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 1.0
x = array.x

返回值:

  • (Object, nil) —如果成功运行则返回对象的x值。

软件版本:

  • SketchUp 6.0

x=方法

x=(x) ⇒ Object

用于设定对象的x坐标值。

示例代码:

array = [1, 2, 3]
# This will initialize the x value as a Float
array.x = 2.5
# This will initialize the x value as a Fixnum
array.x = 5

参数:

  • x (Object) — 新的x坐标值。

返回值:

  • (Object) — 运行成功则返回具有新x坐标值的对象。

软件版本:

  • SketchUp 6.0

y方法

y ⇒ Object?

用于获取对象的y坐标值。

示例代码:

array = [1, 2, 3]
# This will return a Fixnum, in this case 2
y = array.y

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 2.0
y = array.y

返回值:

  • (Object, nil) — 运行成功则返回对象的z坐标值。

软件版本:

  • SketchUp 6.0

y=方法

y=(y) ⇒ Object

用于设定对象的y坐标值。

示例代码:

array = [1, 2, 3]
# This will initialize the y value as a Float
array.y = 2.5
# This will initialize the y value as a Fixnum
array.y = 5

参数:

  • y (Object) — 新的y坐标值。

返回值:

  • (Object) —如果成功运行则返回具有新y坐标的对象。

软件版本:

  • SketchUp 6.0

z方法

z ⇒ Object?

z方法用于提取对象的z坐标。

示例代码:

array = [1, 2, 3]
# This will return a Fixnum, in this case 3
z = array.z

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 3.0
z = array.z

返回值:

  • (Object, nil) — 成功运行则返回对象的z坐标值。

软件版本:

  • SketchUp 6.0

z=方法

z=(z) ⇒ Object

用于设定对象的z坐标值。

示例代码:

array = [1, 2, 3]
# This will initialize the z value as a Float
array.z = 2.5
# This will initialize the z value as a Fixnum
array.z = 5

参数:

  • z (Object) — 新的z坐标位置。

返回值:

  • (Object) — 如果成功运行则返回具有新的Z坐标值的对象

软件版本:

  • SketchUp 6.0