posts - 55,comments - 89,trackbacks - 0

          public class Trigon {

           public static void main(String[] args) {
                  double x1 = 9;
                  double y1 = 9;
                  double x2 = 4;
                  double y2 = 4;
            
            Point sp = new Point(x1,y1);//sp是直線(xiàn)上的一點(diǎn)
            Point tp = new Point(x2,y2);//tp是直線(xiàn)上的另一點(diǎn),也是三角形的頂點(diǎn)
            double arrowWidth = 3;   //設(shè)置三角形的半邊底長(zhǎng)
            double arrowHeight = 6; //設(shè)置三角形的高

            double angle = Math.atan2(tp.y-sp.y, tp.x-sp.x); //求已知直線(xiàn)的傾斜角
            
            System.out.println("該直線(xiàn)的傾斜角度是:" + angle);

            double point_x1 = tp.x-arrowHeight*Math.cos(angle)-arrowWidth*Math.sin(angle);
            double point_y1 = tp.y-arrowHeight*Math.sin(angle)+arrowWidth*Math.cos(angle);

            double point_x2 =tp.x-arrowHeight*Math.cos(angle)+arrowWidth*Math.sin(angle);
            double point_y2 = tp.y-arrowHeight*Math.sin(angle)-arrowWidth*Math.cos(angle);
            
            Point p1 = new Point(point_x1,point_y1);
            Point p2 = new Point(point_x2,point_y2);
            p1.out();
            p2.out();
           }
          }
          //定義定點(diǎn)類(lèi)
          class Point{
           double x;
           double y;
           
           public Point(){}
           public Point(double x, double y){
            this.x = x;
            this.y = y;
           }
           
           public void out(){
            System.out.println("該頂點(diǎn)的X坐標(biāo):" + x);
            System.out.println("該頂點(diǎn)的Y坐標(biāo):" + y);
           }
          }

          參考:http://blog.csdn.net/james999/archive/2008/09/05/2885380.aspx

          posted on 2008-11-12 10:09 jiafang83 閱讀(681) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 封开县| 新化县| 子长县| 青州市| 武功县| 霍州市| 临汾市| 尚志市| 漯河市| 托克托县| 辽阳市| 涿鹿县| 泸西县| 白玉县| 镇平县| 客服| 宁津县| 尼勒克县| 遂平县| 龙口市| 东兴市| 辽中县| 玉林市| 台南县| 岳西县| 云南省| 博乐市| 东宁县| 邵东县| 民和| 南通市| 太湖县| 松滋市| 鄢陵县| 沐川县| 福鼎市| 嘉荫县| 山西省| 元谋县| 驻马店市| 澎湖县|