简体   繁体   English

如何计算等轴测图上两点之间的现实距离?

[英]How to calculate realistic distance between two points on isometric maps?

I'am developing an isometric game, I have to calculate if an item is in the range of another, so in a normal projection a circle would be ok I mean: 我正在开发一个等距游戏,我必须计算一个项目是否在另一个项目的范围内,因此在法线投影中,可以用一个圆圈来表示:

 float dist = sqrt((x1-x2)^2 + (y1-y2)^2);

but as this is an isometric projection where a "x" unit is two times a "y" unity, how could I calculate the range of an item? 但是由于这是一个等轴测投影,其中“ x”单位是“ y”单位的两倍,如何计算项目的范围?

Any tip would be helpful 任何提示都会有所帮助

I'm not sure whether I understand which unit is bigger than the other and in which reference system but one of the below expressions should work: 我不确定我是否了解哪个单位大于另一个单位以及在哪个参考系统中,但以下表达式之一可以工作:

float dist = sqrt(((x1-x2)/2)^2 + (y1-y2)^2);

or 要么

float dist = sqrt((x1-x2)^2 + ((y1-y2)/2)^2);

This is the correct formula: 这是正确的公式:

float dist = sqrt((x2-x1) + (2*(y2-y1))^2);

The y axis is half that of x in isometric. 在等轴测图中,y轴是x轴的一半。

Therefore the distance travelled in y is twice as much in the projection, but note this is not the same as halving the x-distance. 因此,在y中行进的距离是投影中的两倍,但是请注意,这与将x距离减半并不相同。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM