我正在尝试执行代码以使特定的无限数学条件为真。条件为真,则值 = 90 + 360X。其中 X 是一个整数。所以我正在使用单位圆并且只想要等于正 Y 轴的递减。这是一张以橙色突出显示的轴的图片。
例如,角度 90、450、810 等将使条件为真。 如您所见,我已尝试在我的代码中使用 %:
else if (DegreeValue == 90 || ManyRotations90(DegreeValue, 90) == true)
{
Console.WriteLine("Angle(" + DegreeValue + ") lies between the 1st and 2nd quadrant. In other words, it doesn't belong to a specfic section.");
}
static public bool ManyRotations90(double num01, double num02)
{
if (num01 % num02 == 0);
{
return true;
}
return false;
}
即使条件会为这些数字返回 true,它也会为我不想要的数字返回。//这是好的 540 % 90 == 0。但是 270 % 90 == 0//这是不好的。有没有一种方法只适用于 90 + 360X?
最佳答案
您误用了 %
运算符。您需要将度数除以 360(整圈),并检查余数是否为 90:
return DegreeValue % 360 == 90;
关于c# - 包含无限数学方程式的 If 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54087708/