三角函数的效率/速度 [英] Efficiency/speed for trigonometric functions

查看:634
本文介绍了三角函数的效率/速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我做的一个游戏中,我有两点,pt1和pt2,并且我想要弄清它们之间的角度。在早先的计算中,我已经制定了距离。显而易见的方法是在垂直距离上构建水平距离(tan(theta)= opp / adj)。

我想知道,尽管如此已经计算出了距离,使用反正弦/反弧距与距离和dx或dy是否更快?

另外,在表格中进行预先计算可能会更好吗? ?

解决方案

如果您打算执行多次表。性能将会更好。


In a game I'm making, I've got two points, pt1 and pt2, and I want to work out the angle between them. I've already worked out the distance, in an earlier calculation. The obvious way would be to arctan the horizontal distance over the vertical distance (tan(theta) = opp/adj).

I'm wondering though, as I've already calculated the distance, would it be quicker to use arcsine/arccosine with the distance and dx or dy?

Also, might I be better off pre-calculating in a table?

解决方案

If you're going to be doing this many times, pre-calculate in a table. Performance will be much better this way.

这篇关于三角函数的效率/速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆