除了 3D 点之外,是否存在 Point 类的等效项?
我想存储游戏中某些对象的 xy 和 z 坐标,但我找不到像 Point 这样的内置类。是否有一个很好的标准类我可以添加并使用来处理从一个对象到另一个对象的点/方位之间的距离等?
I would like to store the x y and z co-ords for some objects for a game but I can't find a built in class like Point. Is there a nice standard class I could add in and use that would handle distance between points/bearings from one object to another etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最近完成了一些矢量映射(包括 z / 3D),并看到您的 Android 标签,我建议您自己滚动。
原因有很多:
最后,这些原语中的大多数都是相当的易于编写、测试等。您需要编写的主要方法(除了样板构造函数/get/set/...之外)
- 距离
- 点积
- 统一(使各种数学运算的长度== 1)
- 我过去曾使用 DistanceSquared 进行比较函数...这从大多数距离方法中删除了 sqrt 运算符,同时计算对于比较点距离等足够有用的相对距离。
Having recently done some vector mapping (including z / 3D), and seeing your Android tag, I recommend rolling your own.
The reasons are many:
In the end, most of these primitives are quite simple to write, test, etc. The main methods you'll need to write (beyond boilerplate constructor/get/set/...)
- Distance
- Dot product
- Unitize (make length == 1 for various math ops)
- And I've used DistanceSquared in the past for comparison functions... This removes the sqrt operator from most distance methods, while computing a relative distance useful enough for comparing point distances etc.
也许Point3D 正是您所需要的。
Maybe Point3D is what you need.
还有一个 JavaFX 类 Point3D 可以满足您的要求。
There is also a JavaFX class Point3D that meets your requirements.