输入点的数据格式,
号码(String),北坐标(double),东坐标(double),高程(double),代码(String)2,33746.0001,32289.2748,56.234,T2
3,33744.3459,32288.8958,57.234,T3
4,33744.9835,32289.9124,58.234,T4
5,33747.3852,32291.4757,59.234,T5
6,33748.0229,32292.4922,60.234,T6
7,33746.3609,32292.1193,61.234,T7
8,33746.9941,32293.1375,62.234,T8
。比较多。组成线的点:(线是由下面的点按点号顺序连接,如1和2成线,2和3成线,1和3就不可以。)
号码(String),北坐标(double),东坐标(double),高程(double),代码(String)
1,33751.5314,32287.3624,100.234,DCM1
2,33755.7775,32284.7221,101.234,DCM2
3,33760.0235,32282.0817,102.234,DCM3
4,33764.2696,32279.4413,103.234,DCM4
5,33768.091,32277.065,104.234,DCM5
6,33771.4878,32274.9527,105.234,DCM6
7,33773.5272,32273.6881,106.234,DCM7
8,33775.3112,32272.5795,107.234,DCM8
9,33771.6662,32331.6078,108.234,DCM9
比较多。现在想写一个程序区计算上面每个点到下面点组成线的距离并输出,点要在该条线的范围内,既点是在两端点之间。

解决方案 »

  1.   

    我试着定义了点的类,以及点到线的方法。 高手能不能帮我往下走走啊,实在搞定不啊。class svyPoint{
    double sn,se,sz;
    String spt,scd; svyPoint(String pt, double n, double e, double z, String cd){
    this.spt = pt;
    this.scd =cd;
    this.sn = n;
    this.se = e;
    this.sz = z;
    }

    public void p2LineDist(svyPoint line_start,svyPoint line_end,svyPoint p0){

    double a,b,c;

    a = line_end.sn - line_start.sn;
    b = line_start.se - line_end.se;
    c = line_end.se * line_start.sn  - line_start.se *line_end.sn;

    double dist =Math.abs((p0.se * a + p0.sn *b + c)) / Math.sqrt(a*a + b*b);
    System.out.println( "\nDist= "+new DecimalFormat("0.000").format(dist));
    }
    }
      

  2.   

    [Quote=引用 3 楼  的回复:]public class confuse {
    public static void main(String[] args) {   }
    }class svyPoint {
    double n, e, z;
    String pt, cd;svyPoint(String mypt, double myn, double mye, double myz, String mycd) {
    this.pt = mypt;
    this.n = myn;
    this.e = mye;
    this.z = myz;
    this.cd = mycd;
    }public void getDataInfo(svyPoint svypt){
    int i; //indicate the line no;svyPoint[] spt; //each line of data;String[] str = spt.split(",");svypt.pt = parse.str[0];
    svypt.n = parse.str[1];
    svypt.e = parse.str[2];
    svypt.z = parse.str[3];
    svypt.cd =parse.str[4];
    }}
    /*如何把这些数据分开,我用了split,但是达不到目的。
     * 我想把每一行的数据分开如上面的getDataInfo(svyPoint svypt):有上面方法吗?
    1,33745.3625,32288.2582,55.234,T1
    2,33746.0001,32289.2748,56.234,T2
    3,33744.3459,32288.8958,57.234,T3
    4,33744.9835,32289.9124,58.234,T4
    5,33747.3852,32291.4757,59.234,T5
    6,33748.0229,32292.4922,60.234,T6
    7,33746.3609,32292.1193,61.234,T7
    8,33746.9941,32293.1375,62.234,T8
    */ 
    上面的那些是样本数据格式,它需要用数组表示,因为很多。