- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我一直在尝试使用正确的模拟摇杆创建延迟旋转效果。下面的代码根据右模拟摇杆的输入获取角度,并使物体稳定地靠近。由于 atan2 的范围是 -pi 到 pi,变化的旋转总是有利于移动通过 0 弧度而不是 pi。有没有办法让角度向相反的方向移动?
private void Angle()
{
//Angle to go to
RotationReference = -(float)(Math.Atan2(YR, XR));
//Adds on top of rotation to steadily bring it closer
//to the direction the analog stick is facing
Rotation += (RotationReference - Rotation) * Seconds *15;
Console.WriteLine(RotationReference);
}
编辑:
我尝试使用 InBetween 建议的方法,该方法导致 2pi 到 0 之间的转换出现问题。这让我尝试了别的东西。我不知道为什么它不起作用。
private void Angle()
{
//Angle to go to
RotationReference = -(float)(CorrectedAtan2(YR, XR));
//Adds on top of rotation to steadily bring it closer
//to the direction the analog stick is facing
if (Math.Abs(RotationReference - Rotation) > Math.PI)
Rotation += ((float)(RotationReference + Math.PI * 2) - Rotation) * Seconds * 15;
else Rotation += (RotationReference - Rotation) * Seconds *15;
Console.WriteLine(RotationReference);
}
public static double CorrectedAtan2(double y, double x)
{
var angle = Math.Atan2(y, x);
return angle < 0 ? angle + 2 * Math.PI: angle;
}
这背后的想法是,如果您需要行进超过 180 度,您将使行进的角度大于 360 度。这应该消除了反转方向的需要。
最佳答案
只需修正角度以适应 [0, 2·pi]
范围:
public static double CorrectedAtan2(double y, double x)
{
var angle = Math.Atan2(y, x);
return angle < 0 ? angle + 2 * Math.PI : angle;
}
关于c# - 使用 atan2 进行延迟旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37748396/
我必须做一些需要使用三角函数的计算,尤其是 atan一。代码将在 Atmega328p 上运行,为了效率,我不能使用 float s:我使用的是定点数。因此,我不能使用标准 atan功能。 我有一个函
我一直在谷歌上搜索这个问题的解决方案。我见过多种计算任何 -1 #include double my_atan(double x) { return x - (x*x*x)/3 + (x*
我正在用 JavaScript 编写我的第一个项目。据我了解,Math.atan() 返回一个数字(以弧度表示的 Angular )。但不知何故,它返回了 Nan。 使用console.log(),我
我遇到 Math.atan 返回与输入相同的值的问题。 public double inchToMOA( double in, double range){ double rangeI
这里是一位非常初级的程序员(两周前开始),我目前在使用 Math.atan 时遇到问题。我目前使用 Eclipse IDE,并且一直在尝试找出如何对三角形执行 tan^-1,但目前不起作用。我在控制台
下面的代码演示了 atan 的计算时间可以有很大的不同: #include #include #include #include #include #include double get_
我有以下小程序,它在我的大型项目中重现了一个触发错误: #define _USE_MATH_DEFINES #include #include #define R2D(trig_fn, val)
我在我的代码中得到了这个函数: -(void)printAngle { int width = p2_t.x-cp1_t.x; int height = p2_t.y-cp1_t.y;
我有个小问题我不知道如何在 cobol 中转换我的 ATAN/ASIN/ACOS 函数这是代码: ACCEPT A
我试图在点的 Angular 之间做一些比较,但很快我遇到了一些奇怪的结果。 在这个例子中,我尝试旋转线条,使它们指向中心,但线条的 Angular 似乎超过了它们应该很快的 Angular 。然后,
我正在尝试计算一个实体观看另一个实体时必须观察的角度。 l是第一个实体的位置。 o是另一个实体的位置。 每个实体在 3D 空间中都有一个 3D X、Y 和 Z 坐标。 我目前使用 double ang
这个问题已经有答案了: What is the difference between atan and atan2 in C++? (11 个回答) 已关闭 6 年前。 我有一个问题。 atan 和有
我如何将我的 atan 函数放入 atan2 中?例如 float myAtan2(double a, double b) { float atan2val = //calculate ata
Java Math.atan() 函数是否已知有任何问题?我在我的代码中使用它,由于一些我无法解决的奇怪原因,该函数将在 45 度运动时返回 0,跳转到 45 并保持在 45 直到它达到 63.4 度
我在一些基本的触发方面遇到了一些麻烦。我正在做一些数学作业,我终于厌倦了将直角坐标转换为极坐标,反之亦然,所以我决定编写一个小 Python 程序来帮助我进行转换。但是, Math.atan() 给我
我的公式f=arctan(ImZ/ReZ) 有两种选择: 选项 1 (atan): ImZ=-4.593172163003 ImR=-4.297336384845 >>> z=y/x >>> f1=m
atan 和 atan2 都是反正切函数,返回的都是弧度 对于两点形成的直线,两点分别是 point(x1,y1) 和 point(x2,y2),其斜率对应角度的计算方法可以是:
我有一个 2D 侧视射击游戏,我需要一些新的视角。我目前正在研究瞄准,并且它部分有效: Guzzle 速度已知,重力已知,并且到目标的 x,y 距离也已知。使用 SE 和维基百科上的各种来源,我提出了
我在java编程中使用半正矢公式(使用eclipse)。我的问题是在等式的末尾,我收到一个错误(atan 带下划线),指出“方法 atan(double) 对于 Math 类型未定义”。 我不知道出了
所以我想获得2点之间的度数,但是当我希望它返回180时,它返回0...0、90和270确实有效,但是当它180时它返回0..这是我的代码: Location loc1 = new Location(B
我是一名优秀的程序员,十分优秀!