posts - 97,  comments - 93,  trackbacks - 0

          本程序未優化,比較好的方法是,進行曲線積分,算誤差比進行方程約束,由于時間比較少,稍候會給出優化程序。

           1 package com.ibm.nicky.PLR;
           2 
           3 /**
           4  * @author Qu Qiang
           5  * 
           6  */
           7 public class PLR {
           8     public static final double LIMIT = 0.09;
           9 
          10     PLR() {
          11     }
          12 
          13     /**
          14      * @param args
          15      */
          16     public static void main(String[] args) {
          17 
          18         Point[] parray = { new Point(35), new Point(46), new Point(56),
          19                 new Point(66.8), new Point(77.9) };
          20         int temp = 0;
          21         double max = 0.0;
          22         double x1 = parray[0].getX();
          23         double y1 = parray[0].getY();
          24         double x2 = parray[parray.length - 1].getX();
          25         double y2 = parray[parray.length - 1].getY();
          26         double y1my2 = y1 - y2;
          27         double x2mx2 = x2 - x1;
          28         double C = y2 * x1 - y1 * x2;
          29         double length = Math.sqrt(Math.pow((double) (y2 - y1), 2.0)
          30                 + Math.pow((double) (x2 - x1), 2.0));
          31         System.out.println(length);
          32         double d[] = new double[10];
          33         for (int i = 1; i < parray.length - 1; i++) {
          34 
          35             double x = parray[i].getX();
          36             double y = parray[i].getY();
          37 
          38             d[i] = Math.abs(x * y1my2 + y * x2mx2 + C) / length;
          39         }
          40         for (int i = 1; i < parray.length - 1; i++) {
          41             max = d[1];
          42             if (d[i] > max) {
          43                 max = d[i];
          44                 temp = i;
          45             }
          46         }
          47         if (max >= LIMIT) {
          48             System.out.println("this point x=" + parray[temp].getX()
          49                     + " is the target point");
          50         }
          51         double k1 = (parray[temp].getY() - y1) / (parray[temp].getX() - x1);
          52         double k2 = (y2 - parray[temp].getY()) / (x2 - parray[temp].getX());
          53         double b1 = y1 - k1 * x1;
          54         double b2 = y2 - k2 * x2;
          55         System.out.println("the first line is y=" + k1 + "x+" + b1);
          56         System.out.println("the second line is y=" + k2 + "x+" + b2);
          57     }
          58 }



           1 package com.ibm.nicky.plr;
           2 
           3 /**
           4  * @author Qu Qiang
           5  * 
           6  */
           7 
           8 public class Point {
           9     
          10   private double x;
          11   private double y;
          12   Point(double x,double y){
          13       this.x=x;
          14       this.y=y;
          15   }
          16   public double getX(){return this.x;}
          17   public double getY(){return this.y;}
          18 }
          19 

          http://www.gotoread.com/s/e/?vo=1858&p=60
          posted on 2007-08-14 17:27 wqwqwqwqwq 閱讀(1007) 評論(0)  編輯  收藏 所屬分類: Data Structure && Algorithm
          <2007年8月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678




          常用鏈接

          留言簿(10)

          隨筆分類(95)

          隨筆檔案(97)

          文章檔案(10)

          相冊

          J2ME技術網站

          java技術相關

          mess

          搜索

          •  

          最新評論

          閱讀排行榜

          校園夢網網絡電話,中國最優秀的網絡電話
          主站蜘蛛池模板: 介休市| 静海县| 稷山县| 内丘县| 简阳市| 米脂县| 乌鲁木齐县| 那坡县| 全州县| 田林县| 鄂州市| 呼和浩特市| 句容市| 隆德县| 惠州市| 五台县| 南木林县| 祥云县| 肇东市| 永川市| 闽清县| 丹巴县| 阿拉善右旗| 高雄市| 庄河市| 萍乡市| 彭州市| 山阳县| 马公市| 运城市| 嘉兴市| 苏州市| 平阳县| 丰县| 酉阳| 德昌县| 宜春市| 广水市| 平山县| 新丰县| 舒兰市|