直角坐标系点的旋转

借鉴了此篇文章:https://www.cnblogs.com/orange1438/p/4583825.html,但做了小小的改动,原文是逆时针旋转,我实际

需要方位角的旋转是顺时针,所以小作改动。代码如下:

 * @author xue
 *
 */
public class rotatePoint {
	/**
	 * @param p
	 * @param RotAng
	 * @return
	 */
	private point rotatePointUtil(point p,double RotAng) {
		double RotAngF=360-RotAng;
		RotAngF = (RotAngF * Math.PI / 180d);
        double SinVal = (Math.sin(RotAngF));
        double CosVal = (Math.cos(RotAngF));
        double Nx = (p.x * CosVal - p.y * SinVal);
        double Ny = (p.y * CosVal + p.x * SinVal);
        return new point(Nx, Ny);
	}
	
	public static void main(String[] args) {
		/**
		 * 测试
		 */
		point pt=new point(0,10);
		point ptNew;
		double RotAng=30;
	
		rotatePoint rotUtil=new rotatePoint();
		ptNew=rotUtil.rotatePointUtil(pt, RotAng);
		
		System.out.println(ptNew.toString());
	}
}

其中point类如下:

package cn.xue.Algorithm;
public class point {
	public double x;
	public double y;
	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	public point(double x, double y) {
		super();
		this.x = x;
		this.y = y;
	}
	@Override
	public String toString() {
		return "point [x=" + x + ", y=" + y + "]";
	}
	
}

猜你喜欢

转载自blog.csdn.net/u011435933/article/details/80893127