java - 计算 2 个坐标之间的立方体积

标签 java c math cubic

我需要一点帮助。 我基本上想计算世界上两个坐标之间的 block 数,但正如你所见,我不太擅长数学,所以如果你有解决方案,请写给我。 这很重要,所以请写下来,我将不胜感激!

int x1 = 0, y1 = 0, z1 = 0, x2 = 0, y2 = 0, z2 = 0;
x2 = x // pos x in the coord
y2 = y // pos y in the coord
z2 = z // pos z in the coord
x1 = x;
y1 = y;
z1 = z;
int a = Math.abs(Math.abs(x1)-(Math.abs(x2)));
int b = Math.abs(Math.abs(y1)-(Math.abs(y2)));
int c = Math.abs(Math.abs(z1)-(Math.abs(z2)));
if(x2 != 0)
int volume = a*b*c;

最佳答案

a、b、c 的距离不正确。

// int a = Math.abs(Math.abs(x1)-(Math.abs(x2)));
int a = Math.abs(x1 - x2);

当然,正如 @Ted Hopp 所指出的,代码需要一些除 0 之外的有趣值来完成很多工作。

int x1 = 0, y1 = 0, z1 = 0, x2 = 0, y2 = 0, z2 = 0;

关于java - 计算 2 个坐标之间的立方体积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26080344/

相关文章:

c++ - 如何使用某些参数展开某个循环,例如 GCC 中的 max-unroll-times

c - 在 C 中使用 strcmp 和 bubblesort 对二维数组进行排序

python - 使用 python 的 ** 运算符和 * 运算符时进行签名

java - getResources() 上的 nullPoint 异常

Java - If 语句不起作用(比较字符串)

java - spring-boot-gradle-plugin 是否随 spring-boot 版本一起移动?

java - hibernate 可选择不自动递增 ID 字段

c - 将 X 索引的内存复制到 C 中单个数组中的多个位置的最佳方法是什么?

sql-server - 如何计算 SQL 中 float 的模数?

math - 绘制旋转矩形