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 阅读(994) 评论(0)  编辑  收藏 所属分类: Data Structure && Algorithm

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


网站导航:
 
<2007年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678




常用链接

留言簿(10)

随笔分类(95)

随笔档案(97)

文章档案(10)

相册

J2ME技术网站

java技术相关

mess

搜索

  •  

最新评论

阅读排行榜

校园梦网网络电话,中国最优秀的网络电话