Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 求圆的对角_C#_Visual Studio 2015 - Fatal编程技术网

C# 求圆的对角

C# 求圆的对角,c#,visual-studio-2015,C#,Visual Studio 2015,我试着编码一个从0到359的随机角度,然后从这个随机角度得到相反的角度 double? AngleNoCur = randomAngle ? Random.Next(0, 359) : angle * Math.PI / 180; //'angle' is used for something else, ignore it double? fixedAngleOpposite = AngleNoCur <= 179 ? AngleNoCur + 180 * Math.PI / 180 :

我试着编码一个从0到359的随机角度,然后从这个随机角度得到相反的角度

double? AngleNoCur = randomAngle ? Random.Next(0, 359) : angle * Math.PI / 180; //'angle' is used for something else, ignore it
double? fixedAngleOpposite = AngleNoCur <= 179 ? AngleNoCur + 180 * Math.PI / 180 : AngleNoCur - 180 * Math.PI / 180;
double?AngleNoCur=随机角度?Random.Next(0359):角度*Math.PI/180;/'“角度”用于其他对象,忽略它

双重的FixedAngleAntivative=AngleNoCur我认为你被与辐射相混淆了。公式
AngleNoCur+180*Math.PI/180
对我来说没有多大意义-你把180除以180再乘以π。。。我想你希望你的结果是以度为单位的,所以只需留下那部分——180已经是以度为单位的了。那么它看起来是这样的:

double? fixedAngleOpposite = AngleNoCur <= 179 ? AngleNoCur + 180 : AngleNoCur - 180;
但是,如果希望最终获得辐射度,可以使用以下方法:

fixedAngleOpposite *= Math.PI / 180;
事实上,我认为你一直想要使用辐射度,因为你把角度转换成了辐射度,不管它是什么,我们应该忽略它。然后,您的
固定角度相反的部分应该可以工作,但您应该更改角度曲线:

double? AngleNoCur = randomAngle ? Random.Next(0, 359) * Math.PI / 180 : angle * Math.PI / 180;
但是,我仍然建议对
fixedangleabsolute
使用模,您可以缩短方程式:

double? fixedAngleOpposite = (AngleNoCur + Math.PI) % (2 * Math.PI);
有关度和辐射度的更多信息,我建议通读以下内容:。
关于模的更多信息,请看一下:。

相反的角度不是360度吗?@DavidG-Nope,我不这么认为。想象一下1°@元克隆的角度是的,那是359then@DavidG所以它不会是相反的,是吗?让我们来看看。我很确定我需要X=host.X+(float)(range*Math.Cos(fixedangleabsolute.Value)),Y=host.Y+(float)(range*Math.Sin(fixedangleabsolute.Value)),我会尝试一下。好吧,你用的是弧度,所以你应该转换回弧度。我将更新我的帖子以再次获得radiants。
double? fixedAngleOpposite = (AngleNoCur + Math.PI) % (2 * Math.PI);