随笔 - 23  文章 - 15  trackbacks - 0
<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011



留言簿(3)

随笔分类(19)

搜索

  •  

最新随笔

最新评论

阅读排行榜

评论排行榜

如图


就是一个四边形(A,B,C,D),从倾斜于中点旋转到水平处
求其A点的新座标
已知A点坐标,四边形各边长,旋转角度

实现源代码java:

package com.math;
/**
 * 表示坐标点类
 * 说明: 其中的xAsix 表示的是X轴
 *         其中的yAsix 表示的是y轴
 * 
@author jiadong
 *
 
*/

public class Coordinate{
    
private float xAxis ;
    
private float yAxis;
    
public Coordinate(float xAxis,float yAxis){
        
this.xAxis = xAxis;
        
this.yAxis = yAxis;
    }

    
public Coordinate(){}
    @Override
    
public String toString() {
        
return "("+xAxis+""+yAxis+")";
    }

    
public float getXAxis() {
        
return xAxis;
    }

    
public void setXAxis(float axis) {
        xAxis 
= axis;
    }

    
public float getYAxis() {
        
return yAxis;
    }

    
public void setYAxis(float axis) {
        yAxis 
= axis;
    }

}




package com.math;

import junit.framework.TestCase;
/**
 * 思路:
 *  先求得中心点的坐标,加入中心点坐标为原点坐标
 *  那么求得结果应该为(-b/2,o)
 *  按照这个道理,把中心坐标平移量求的
 *  在把(-b/2,o) 按照平移量 平移即所得结果
 * 
@author jiadong
 *  @time 2008年9月19日
 
*/

public class MathDemo extends TestCase{
    
/* b,d */
    
private float width = 4 ;
    
/**a ,c **/
    
private float higth = 3 ;
    
    
private float angle = 90;
    
private Coordinate aOld = new Coordinate(2,1.5f);
    
    
private double ang = angle*Math.PI/180;
    
public void testsetCoordinateCenter(){
        
//先求出中心点的坐标来
        
//按照B点C点的中心位置为中心点坐标点思路来求得
        float tempX = (float) (width * Math.cos(ang));
        
float tempY = (float) (width * Math.sin(ang));
        
//求得B点的坐标
        Coordinate B_cd = new Coordinate();
        B_cd.setXAxis(aOld.getXAxis()
+tempX);
        B_cd.setYAxis(aOld.getYAxis()
-tempY);
        
float tempXX = (float)(higth *Math.sin(ang));
        
float tempYY = (float)(higth *Math.cos(ang));
        
//求得C点的坐标
        Coordinate C_cd = new Coordinate();
        C_cd.setXAxis(aOld.getXAxis()
+tempXX);
        C_cd.setYAxis(aOld.getYAxis()
-tempYY);
        
//得出中心点的坐标
        Coordinate center = new Coordinate();
        center.setXAxis((B_cd.getXAxis()
+C_cd.getXAxis())/2);
        center.setYAxis((B_cd.getYAxis()
-C_cd.getYAxis())/2);
        
//得出最终的结果
        Coordinate aNew = new Coordinate();
        aNew.setXAxis(center.getXAxis()
-width/2);
        aNew.setYAxis(center.getYAxis());
        System.out.println(aNew);
    }

}

posted on 2008-09-19 13:28 jiadong 阅读(2775) 评论(1)  编辑  收藏

FeedBack:
# re: 矩形旋转坐标点的问题 2008-09-19 13:30 jiadong
其中需要注意到地方就是 Math这个类里面的方法,在求sin ,cos 以及别的三角函数的时候,传入的参数是弧度值,所以需要把角度转换为弧度后在计算

所以就有了上述的private double ang = angle*Math.PI/180;
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: