본문 바로가기
프로그래밍/Android-Java

[ANDROID] 두 점의 각도 구하기

by 채연2 2020. 11. 17.

두 점의 각도 구하는 방법

 

public static double angleOf(PointF p1, PointF p2) {
	// NOTE: Remember that most math has the Y axis as positive above the X.
	// However, for screens we have Y as positive below. For this reason,
	// the Y values are inverted to get the expected results.
	final double deltaY = (p1.y - p2.y);
	final double deltaX = (p2.x - p1.x);
	final double result = Math.toDegrees(Math.atan2(deltaY, deltaX));
	return (result < 0) ? (360d + result) : result;
}
320x100

댓글