Vector2 / Vector4

Vector2, Vector4 — Aspose.3D TypeScript API Reference

Gói: @aspose/3d (v24.12.0)

Vector2Vector4 là các kiểu vector độ chính xác gấp đôi được xuất ra từ @aspose/3d/utilities. Vector2 là kiểu tọa độ 2D tiêu chuẩn cho dữ liệu UV. Vector4 là kiểu đồng nhất 4 thành phần được sử dụng cho các điểm điều khiển lưới và mảng dữ liệu phần tử đỉnh.

import { Vector2, Vector4 } from '@aspose/3d';

Enumerations

Một vector độ chính xác gấp đôi gồm hai thành phần với xy các trường.

export class Vector2

Enumerations

new Vector2(x: number = 0.0, y: number = 0.0)

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
xnumberđọc/ghiThành phần đầu tiên (ngang).
ynumberđọc/ghiThành phần thứ hai (dọc).
lengthnumberđọcĐộ dài Euclid: sqrt(x² + y²).
length2numberđọcĐộ dài bình phương: x² + y². Rẻ hơn length khi so sánh khoảng cách.

Enumerations

set(x, y)

Đặt cả hai thành phần tại chỗ.

set(newX: number, newY: number): void

getItem(key) / setItem(key, value)

Truy cập dựa trên chỉ mục; key phải là 0 hoặc 1.

equals(other)

So sánh bằng nhau từng thành phần.

equals(other: Vector2): boolean

Vector2.parse(input) (tĩnh)

Phân tích một chuỗi phân tách bằng dấu cách "x y" thành một Vector2.

static parse(input: string): Vector2

toString()

Enumerations "Vector2(x, y)".

Enumerations

import { Vector2 } from '@aspose/3d';

const uv = new Vector2(0.5, 0.25);
console.log(uv.x, uv.y);       // 0.5 0.25
console.log(uv.length);        // ~0.559

const uv2 = Vector2.parse('0.0 1.0');
console.log(uv2.equals(new Vector2(0.0, 1.0)));  // true

uv.set(1.0, 0.0);
console.log(uv.toString());    // Vector2(1, 0)

Enumerations

Một vector bốn thành phần độ chính xác kép với x, y, z, và w các trường. Được sử dụng làm kiểu phần tử của Mesh.controlPoints và các mảng dữ liệu phần tử đỉnh.

export class Vector4

Enumerations

new Vector4()
new Vector4(x: number, y: number, z: number, w: number)
new Vector4(vec3: FVector3, w: number)
new Vector4(vec: FVector2, w: number)

Constructor mặc định tạo ra (0, 0, 0, 1). Khi khởi tạo từ FVector3, thì xyz các thành phần được lấy từ vector và w được cung cấp làm đối số thứ hai.

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
xnumberđọc/ghiThành phần đầu tiên.
ynumberđọc/ghiThành phần thứ hai.
znumberđọc/ghiThành phần thứ ba.
wnumberđọc/ghiThành phần thứ tư (đồng nhất). Đối với dữ liệu vị trí, w1.0.

Enumerations

set(x, y, z, w?)

Đặt tất cả các thành phần vào vị trí. w mặc định là 1.0.

set(newX: number, newY: number, newZ: number, newW: number = 1.0): void

getItem(key) / setItem(key, value)

Truy cập dựa trên chỉ mục; key phải là 03.

equals(other)

Bằng nhau theo từng thành phần.

toString()

Enumerations "Vector4(x, y, z, w)".

Enumerations

import { Vector4 } from '@aspose/3d';

// Used as mesh control points
const v = new Vector4(1.0, 0.0, 0.0, 1.0);
console.log(v.w);    // 1.0

// Index access
console.log(v.getItem(0));   // 1.0
v.setItem(1, 2.0);
console.log(v.y);            // 2.0

Điền các điểm điều khiển lưới:

import { Scene, Mesh, Vector4 } from '@aspose/3d';

const mesh = new Mesh();
mesh.controlPoints.push(new Vector4(0.0, 0.0, 0.0, 1.0));
mesh.controlPoints.push(new Vector4(1.0, 0.0, 0.0, 1.0));
mesh.controlPoints.push(new Vector4(0.5, 1.0, 0.0, 1.0));
mesh.createPolygon(0, 1, 2);

const scene = new Scene();
scene.rootNode.createChildNode('triangle', mesh);
scene.save('triangle.glb');

Xem Thêm

 Tiếng Việt