中心点を中心に回転した点の座標を計算します。
638 ワード
開発中に座標変換のアルゴリズム問題に出会い、ようやく解決しました。ここで共有します。
javaコードの実装は以下の通りです。
javaコードの実装は以下の通りです。
private static Point calcNewPoint(Point p, Point pCenter, float angle) {
// calc arc
float l = (float) ((angle * Math.PI) / 180);
//sin/cos value
float cosv = (float) Math.cos(l);
float sinv = (float) Math.sin(l);
// calc new point
float newX = (float) ((p.x - pCenter.x) * cosv - (p.y - pCenter.y) * sinv + pCenter.x);
float newY = (float) ((p.x - pCenter.x) * sinv + (p.y - pCenter.y) * cosv + pCenter.y);
return new Point((int) newX, (int) newY);
}