안녕하세요. 저는 두 벡터 사이의 각도를 계산하고 있으며 때로는 Math.Acos()가 코사인에 대해 범위를 벗어났습니다 (-1> 입력 & & 입력> 1) NaN을 반환합니다. 그게 정확히 무슨 뜻 이죠? 누군가 무슨 일이 일어 났는지 설명 할 수 있습니까? 어떤 도움을 주셔서 감사합니다!Math.Acos()가 잘못된 입력을보고하는 상황을 어떻게 해석합니까?
public double AngleBetween(vector b)
{
var dotProd = this.Dot(b);
var lenProd = this.Len*b.Len;
var divOperation = dotProd/lenProd;
// http://msdn.microsoft.com/en-us/library/system.math.acos.aspx
return Math.Acos(divOperation) * (180.0/Math.PI);
}
여기 Dot
및 Len
내 구현의 :
public double Dot(vector b)
{
// x's and y's are lattitudes and longitudes (respectively)
return (this.From.x*b.From.x + this.From.y*b.From.y);
}
public double Len{
get
{
// geo is of type SqlGeography (MS SQL 2008 Spatial Type) with an SRID of 4326
return geo.STLength().Value;
}
}
nitpick : 경계 조건은'(-1> input || input> 1)'또는'! (- 1 <= input && input <= 1)'이라고 써야합니다. – MatrixFrog
그러나 (위도, 경도) 쌍은 2D 벡터가 아니며 3D로 각도를 측정 한 것입니다. 그래서 무엇을 찾으려고하니? 아마도 지구의 중심에서의 내부 각도 또는이 둘 사이의 베어링일까요? 이 공식은 당신을 얻지 못할 것입니다. –
또한 '보낸 사람'은 무엇입니까? 2D Vector 객체의 경우 x 및 y 값을 포함하고 Dot 메서드는 this.X * other.X + this.Y * other.Y가 될 것으로 기대합니다. 또한 Len 메소드가 sqrt (x * x + y * y)를 돌려 줄 것이라고 기대할 수 있습니다. –