You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dart中是否存在适用于整数的Vector3类替代方案?

整数三维坐标类的实现方案

vector_math_64库中没有提供专门处理整数的三维坐标类,你可以在自己定义的Coordinates类基础上补充所需的实用方法,比如distanceTo,示例如下:

import 'dart:math';

class Coordinates {
  int x, y, z;

  Coordinates(this.x, this.y, this.z);

  // 计算到目标坐标的欧几里得距离
  double distanceTo(Coordinates other) {
    final dx = x - other.x;
    final dy = y - other.y;
    final dz = z - other.z;
    return sqrt(dx * dx + dy * dy + dz * dz);
  }

  // 可选:添加曼哈顿距离计算(适合网格场景)
  int manhattanDistanceTo(Coordinates other) {
    return (x - other.x).abs() + (y - other.y).abs() + (z - other.z).abs();
  }

  // 可选:实现坐标加法运算
  Coordinates operator +(Coordinates other) {
    return Coordinates(x + other.x, y + other.y, z + other.z);
  }

  // 可选:实现坐标减法运算
  Coordinates operator -(Coordinates other) {
    return Coordinates(x - other.x, y - other.y, z - other.z);
  }

  @override
  String toString() => 'Coordinates(x: $x, y: $y, z: $z)';
}

你可以根据实际需求继续扩展更多方法,比如标量乘法、点积计算等,完全复刻Vector3的实用特性。

内容的提问来源于stack exchange,提问作者Velter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 19:42:34