一个点  point(double ,double)一个平面( 由N多个 point(double,double)组成 ),若干个点, 用直线联起来, 组成一个区域,看所求的点是否在这个区域内.
判断  一个点是否在  这个平面内?
能做的高手,想做的朋友都可以叫我拿数据!!留下  email我发!目前找到了一个  awt的Polygon 来使用,我把数据都乘以10的6次方,不知道有没有更好的方法? 

解决方案 »

  1.   

    package com.ginwave.gps.common;import java.util.ArrayList;
    import java.util.List;/**
     * 报警区域区具类
     * 
     * @author yebing
     * 
     */
    public class AlarmAreaUtil { /**
     * 判断点是否在多边形面内
     * 
     * @param px
     * @param py
     * @param polygonXA
     * @param polygonYA
     * @return
     */
    public static boolean isPointInPolygon(double px, double py, List<Double> polygonXA, List<Double> polygonYA) {
    boolean isInside = false;
    double ESP = 1e-9;
    int count = 0;
    double linePoint1x;
    double linePoint1y;
    double linePoint2x = 180;
    double linePoint2y; linePoint1x = px;
    linePoint1y = py;
    linePoint2y = py; for (int i = 0; i < polygonXA.size() - 1; i++) {
    double cx1 = polygonXA.get(i);
    double cy1 = polygonYA.get(i);
    double cx2 = polygonXA.get(i + 1);
    double cy2 = polygonYA.get(i + 1);
    if (isPointOnLine(px, py, cx1, cy1, cx2, cy2)) {
    return true;
    }
    if (Math.abs(cy2 - cy1) < ESP) {
    continue;
    } if (isPointOnLine(cx1, cy1, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
    if (cy1 > cy2)
    count++;
    } else if (isPointOnLine(cx2, cy2, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
    if (cy2 > cy1)
    count++;
    } else if (isIntersect(cx1, cy1, cx2, cy2, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
    count++;
    }
    }
    if (count % 2 == 1) {
    isInside = true;
    } return isInside;
    } private static double Multiply(double px0, double py0, double px1, double py1, double px2, double py2) {
    return ((px1 - px0) * (py2 - py0) - (px2 - px0) * (py1 - py0));
    } private static boolean isPointOnLine(double px0, double py0, double px1, double py1, double px2, double py2) {
    boolean flag = false;
    double ESP = 1e-9;
    if ((Math.abs(Multiply(px0, py0, px1, py1, px2, py2)) < ESP) && ((px0 - px1) * (px0 - px2) <= 0) && ((py0 - py1) * (py0 - py2) <= 0)) {
    flag = true;
    }
    return flag;
    } private static boolean isIntersect(double px1, double py1, double px2, double py2, double px3, double py3, double px4, double py4) {
    boolean flag = false;
    double d = (px2 - px1) * (py4 - py3) - (py2 - py1) * (px4 - px3);
    if (d != 0) {
    double r = ((py1 - py3) * (px4 - px3) - (px1 - px3) * (py4 - py3)) / d;
    double s = ((py1 - py3) * (px2 - px1) - (px1 - px3) * (py2 - py1)) / d;
    if ((r >= 0) && (r <= 1) && (s >= 0) && (s <= 1)) {
    flag = true;
    }
    }
    return flag;
    } public static void main(String[] args) {
    //AlarmAreaUtil util = new AlarmAreaUtil();
    List<Double> list1 = new ArrayList<Double>();
    list1.add(-1D);
    list1.add(-1D);
    list1.add(1D);
    list1.add(2D);
    List<Double> list2 = new ArrayList<Double>();
    list2.add(1D);
    list2.add(-1D);
    list2.add(-1D);
    list2.add(2D);
    //System.out.println(util.isPointInPolygon(1D, 1D, list1, list2));
    }
    }
    我也是做GIS的,希望上面的代码给你有帮助.