이 기사의 예제는 Java의 특정 코드를 공유하여 포인트가 참조를 위해 그려진 범위 내에 있는지 여부를 결정합니다. 특정 내용은 다음과 같습니다
isptinpoly.java
패키지 com.ardo.util.circle; java.util.arraylist 가져 오기; Java.util.list 가져 오기; /*** java는 점이 그려진 범위 내에 있는지 여부를 결정합니다 (poly 【【isptinpoly】/circle 【distencepc】)* @param point detection point* @param pts vertex* @param pts vertex* @return point는 다각형에서 true를 반환합니다. 검출 지점* @param pts vertex의 다각형* @return Point는 다각형에서 true를 반환합니다. 그렇지 않으면 false*/ public static boolean isptinpoly (point2d point, list <point2d> pts) {int n = pts.size (); 부울 바운드버 텍스 = true; // 포인트가 다각형의 정점 또는 가장자리에 있으면 다각형의 점으로 간주 될 수 있으며, 직접 반환됩니다 int intersectCount = 0; // X Double Precision = 2E-10; // 부동 소수점 유형 동안 0과 비교할 때의 공차 계산 Point2d P1, P2; // 인접 경계 정점 Point2d P = Point; // 현재 포인트 p1 = pts.get (0); // 왼쪽 정점 (int i = 1; i <= n; ++ i) {// 모든 광선을 확인하면 (p.equals (p1)) {return boundorvertex; // p는 vertex} p2 = pts. Math.Max (P1.X, P2.X)) {// RAY는 우리의 관심사를 벗어납니다. P1 = P2; if (px> math.min (p1.x, p2.x) && px <math.max (p1.x, p2.x)) {// ray는 알고리즘 (공통 부분)에 의해 교차됩니다. if (py <= math.max (p1.y, p2.y)) {// x는 (p1 = x) if (p1.x if if (p1.x) if (p1.x). math.min (p1.y, p2.y)) {// 수평 광선에서 오버링되면 BoundorVertex; } if (p1.y == p2.y) {// ray는 수직 if (p1.y == py) {// 수직 Ray Return BoundOrverTex에서 오버링됩니다. } else {// ray ++ intersectCount 이전; }} else {// 왼쪽의 크로스 포인트 double xinters = (px -p1.x) * (p2.y -p1.y)/(p2.x -p1.x) + p1.y; // y if (math.abs (py -xinters) <정밀) {// 광선 반환의 경계선; } if (py <xinters) {// ray ++ intersectCount 이전; }}}} else {// Ray가 정점을 통과하는 경우 (px == p2.x && py <= p2.y) {// p p2 point2d p3 = pts.get ((i+1) % n); // 다음 정점 if (px> = math.min (p1.x, p3.x) && px <= math.max (p1.x, p3.x)) {// px는 p1.x 사이에 있습니다. & p3.x ++ intersectcount; } else {intersectCount += 2; }}} p1 = p2; // 다음 광선 왼쪽 지점} if (intersectCount % 2 == 0) {// 숫자가 다각형 외부에 있습니다. } else {// 홀수 숫자는 다각형 반환 내부에 있습니다. }}/** * 원 안에 있는지 여부를 결정하십시오 * @param p * @param c * @return */public static string distonpc (point2d p, circle c) {// 원의 점과 원의 중심 사이의 거리와 원의 중심 사이의 관계를 판단합니다. double d2 = math.hypot ((p.getx () -c.getcc (). getx ()), (p.gety () -c.getcc (). gety ())); System.out.println ( "d2 =="+d2); double r = c.getr (); if (d2> r) {s = "원 밖에 서클 외부"; } else if (d2 <r) {s = "원 안에"; } else {s = "원에서"; } 반환 s; } public static void main (String [] args) {point2d point = new Point2d (116.404072, 39.916605); // 포인트가 다각형 목록 내부에 있는지 테스트합니다. <point2d> pts = new ArrayList <Point2d> (); pts.add (New Point2d (116.395, 39.910)); pts.add (New Point2d (116.394, 39.914)); pts.add (New Point2d (116.403, 39.920)); pts.add (New Point2d (116.402, 39.914)); pts.add (New Point2d (116.410, 39.913)); if (isptinpoly (point, pts)) {System.out.println ( "포인트 안에 있습니다"); } else {system.out.println ( "포인트는 다각형 외부"); } // 포인트가 Circle Point2d CenterPoint 안에 있는지 테스트합니다. Circle C = New Circle (); C.SETCC (CenterPoint); C. 세트 (0.0056); 문자열 s = distonpc (point, c); System.out.println ( ""원의 요점 : "+s); }} Circle.java
/ ** * 원형 클래스 * @Author Ardo * */ public class circle {private double r; Private Point2d CC; 공공 공간 setr (double a) {r = a; } public void setcc (point2d centerofcir) {cc = centerofcir; } public double getr () {return r; } public point2d getcc () {return cc; }} Point2d.java
공개 클래스 Point2d {public double x; 공개 이중 Y; public point2d (double x, double y) {super (); this.x = x; this.y = y; } public double getx () {return x; } public void setx (double x) {this.x = x; } public double gety () {return y; } public void sety (double y) {this.y = y; }}위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.