HW3 Angle between two vectors

If v1 and v2 are normalised so that |v1|=|v2|=1, then angle = acos(v1•v2)

http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/

// 세 점으로부터 도형의 내각 구하기
public static double InnerAngle(Point p1, Point p2, Point p3)
{
Point v1 = new Point(p1.X – p2.X, p1.Y – p2.Y); // v1 = p1 – p2
Point v2 = new Point(p3.X – p2.X, p3.Y – p2.Y); // v2 = p3 – p2
double len1 = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y); // v1.Length()
double len2 = Math.Sqrt(v2.X * v2.X + v2.Y * v2.Y); // v2.Length()
double nx1 = v1.X / len1; // n1 = v1.Normalize
double ny1 = v1.Y / len1;
double nx2 = v2.X / len2; // n2 = v2.Normalize
double ny2 = v2.Y / len2;
double dot = (nx1 * nx2) + (ny1 * ny2); // DotProduct(n1, n2)
double radian = Math.Acos(dot);
return (radian * 180.0 / Math.PI); // RadianToDegree
}

// 두 점 간의 거리 구하기

public static double Distance(Point p, Point q)
{
return Math.Sqrt((p.X – q.X) * (p.X – q.X) + (p.Y – q.Y) * (p.Y – q.Y));
}

Leave a Reply

Your email address will not be published. Required fields are marked *