FVector2, FVector3, FVector4 — Aspose.3D Python API Reference
包:: aspose.threed.utilities (aspose-3d-foss 26.1.0)
Properties FVector 类型是单精度 (float32) 向量类,内部用于顶点元素数据数组。它们在单精度的内存效率与双精度的 Vector2, Vector3, Vector4 用于场景图位置的类。实际上,你通常会在填充时创建这些值 VertexElementFVector.set_data().
from aspose.threed.utilities import FVector2, FVector3, FVector4FVector2
一个具有两个分量的单精度浮点向量,包含 x 和 y 分量。.
class FVector2:
def __init__(self, x: float = 0.0, y: float = 0.0): ...Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
x | float | 读/写 | 第一组件。. |
y | float | 读/写 | 第二组件。. |
Properties
| Properties | Properties | Properties |
|---|---|---|
length() | float | 向量的欧几里得长度:: sqrt(x² + y²). |
normalize() | FVector2 | 返回一个单位长度的副本。返回 FVector2(0, 0) 对零向量。. |
dot(other) | float | 与…的点积 other. |
FVector2.parse(s) | FVector2 | 解析一个以空格分隔的字符串 "x y" 为一个 FVector2. |
Properties +, -, * (标量), / (标量),以及 == 运算符。.
Properties
from aspose.threed.utilities import FVector2
uv = FVector2(0.5, 0.25)
print(uv.x, uv.y) # 0.5 0.25
print(uv.length()) # ~0.559
unit = uv.normalize()
print(round(unit.length(), 6)) # 1.0
a = FVector2(1.0, 0.0)
b = FVector2(0.0, 1.0)
print(a.dot(b)) # 0.0FVector3
一个带有三个分量的单精度浮点向量 x, y,,以及 z 分量。.
class FVector3:
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0): ...FVector3 也接受一个 Vector3, Vector4,,或 FVector4 作为其第一个参数,以从这些类型进行转换。.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
x | float | 读/写 | 第一组件。. |
y | float | 读/写 | 第二组件。. |
z | float | 读/写 | 第三个分量。. |
支持索引访问:: v[0], v[1], v[2].
静态工厂方法
| Properties | Properties | Properties |
|---|---|---|
FVector3.zero() | FVector3 | (0, 0, 0) |
FVector3.one() | FVector3 | (1, 1, 1) |
FVector3.unit_x() | FVector3 | (1, 0, 0) |
FVector3.unit_y() | FVector3 | (0, 1, 0) |
FVector3.unit_z() | FVector3 | (0, 0, 1) |
实例方法
| Properties | Properties | Properties |
|---|---|---|
normalize() | FVector3 | 返回一个单位长度的副本。对于零长度输入,返回零向量。. |
Properties
from aspose.threed.utilities import FVector3
n = FVector3(0.0, 1.0, 0.0)
print(n.normalize()) # FVector3(0.0, 1.0, 0.0)
up = FVector3.unit_y()
print(up.x, up.y, up.z) # 0.0 1.0 0.0
# Convert from Vector3
from aspose.threed.utilities import Vector3
v = Vector3(1.0, 2.0, 3.0)
fv = FVector3(v)
print(fv) # FVector3(1.0, 2.0, 3.0)FVector4
一个具有四个分量的单精度浮点向量, x, y, z,,和 w 组件。这是所使用的存储类型 VertexElementFVector.data.
class FVector4:
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 0.0): ...FVector4 也接受一个 FVector3, Vector3,,或 Vector4 作为它的第一个参数。.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
x | float | 读/写 | 第一组件。. |
y | float | 读/写 | 第二组件。. |
z | float | 读/写 | 第三组件。. |
w | float | 读/写 | 第四个组件。. |
支持索引访问:: v[0] 通过 v[3].
Properties
from aspose.threed.utilities import FVector4, FVector3
# Direct construction
normal = FVector4(0.0, 0.0, 1.0, 0.0)
print(normal.z) # 1.0
# From FVector3
fv3 = FVector3(0.0, 1.0, 0.0)
fv4 = FVector4(fv3, 0.0)
print(fv4) # FVector4(0.0, 1.0, 0.0, 0.0)
# Index access
print(fv4[1]) # 1.0
fv4[3] = 1.0
print(fv4.w) # 1.0与双精度向量的关系
| 单精度 | 双精度 | 常见用法 |
|---|---|---|
FVector2 | Vector2 | UV 坐标存储在顶点元素中 |
FVector3 | Vector3 | 法线、切线存储在顶点元素中 |
FVector4 | Vector4 | Properties VertexElementFVector.data 条目;也包括控制点转换 |
在设置顶点元素数据时,您可以传递任一精度类。. set_data() 转换 Vector2/Vector3 值到 FVector4 自动地.