识别 3d 笛卡尔图中网格线与直线相交的所有点
我正在使用 PHP 并生成了一个 3D 笛卡尔坐标系 (x,y,z)。我想在两点之间走一条直线。我将每个 1x1x1 的正方形称为由最接近原点的相邻格点标识的扇区。我试图识别线段经过的每个扇区。
以下帖子很有帮助,但由于它涉及 2D 系统,因此并不完全是我所需要的。
谢谢杰森
I'm using PHP and have generated a 3D cartesian coordinate system (x,y,z). I want to travel a straight line between two points. I call each 1x1x1 square a sector identified by the adjacent lattice point closest to the origin. I'm trying to identify each sector that the line segment passes through.
The following post was helpful, but since it deals with 2D systems, wasn't exactly what I needed.
PHP Find Coordinates between two points
Thanks
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是 PHP 专家,但这对于 3d 系统来说是相同的解决方案:
I am not an expert for the PHP, but this is the same solution for the 3d system:
我不是专家,但一种(愚蠢的?)方法是编写一个函数来查找两个坐标的“中点”((x1 + x2)/2,(y1 + y2)/2,(z1 + z2) )/2),然后将它们舍入以获得真正的坐标。现在,您只需递归地将函数应用于所有腿,直到没有新的中间点,就可以找到整条“线”。
I'm no expert, but one (stupid?) approach would be to write a function which finds the 'middle point' of two coordinates ((x1 + x2)/2, (y1 + y2)/2, (z1 + z2)/2), then round them to get a real coordinate. Now you could find the whole 'line' by just recursively apply the function to all legs until there's no new middle point.