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是直線上的一點
            Point tp = new Point(x2,y2);//tp是直線上的另一點,也是三角形的頂點
            double arrowWidth = 3;   //設置三角形的半邊底長
            double arrowHeight = 6; //設置三角形的高

            double angle = Math.atan2(tp.y-sp.y, tp.x-sp.x); //求已知直線的傾斜角
            
            System.out.println("該直線的傾斜角度是:" + 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();
           }
          }
          //定義定點類
          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("該頂點的X坐標:" + x);
            System.out.println("該頂點的Y坐標:" + y);
           }
          }

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

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

          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           
          主站蜘蛛池模板: 文成县| 丹巴县| 博湖县| 鄂托克前旗| 衡阳县| 永吉县| 将乐县| 资溪县| 西华县| 阳信县| 武隆县| 吉林省| 赤峰市| 六安市| 三河市| 绥棱县| 东城区| 仁怀市| 阜平县| 渝中区| 尼玛县| 炎陵县| 赣榆县| 宁蒗| 宜良县| 济宁市| 五寨县| 南雄市| 咸阳市| 兴和县| 景泰县| 新巴尔虎左旗| 杭锦旗| 阳山县| 永德县| 乐东| 定兴县| 汪清县| 于都县| 新野县| 平和县|