2010-08-19 3 views
1

나는 안드로이드 맵을 사용하여 몇 가지 고급 기능을 수행하려고 노력 중이며 벡터에서 일부 작업을 수행해야합니다. 이제 - this에서 대답을 읽고 나에게 힌트와 팁을주었습니다. 그러나 이해할 수없는 부분이 있습니다.Android지도에서 2 점을 사용하여 벡터를 결정하는 방법은 무엇입니까?

광선의 시작점과 끝점 좌표가 이제부터 "다각형 내의 점"에서 "광선과 다각형면이 교차하는 빈도"로 문제가 이동합니다. 그러므로 우리는 이전처럼 (바운딩 박스의 경우) 다각형 점으로 작업 할 수 없습니다. 이제 실제면이 필요합니다. 한면은 항상 두 점으로 정의됩니다.

1면 (X1/Y1) - (X2/Y2) 측 2 : (X2/Y2) - (X3/Y3) 측 3 (X3/Y3) - (X4/Y4)

내 이해는 삼각형의 모든면이 실제로는 벡터라는 것입니다. 그러나 2 점을 빼는 것이 어떻게 가능합니까? A (1,1), B (2,2), C (1,3)과 같이 3 개의 꼭지점이있는 삼각형이 있다고 가정 해 봅시다. 그래서 저는 한면을 계산하기 위해 (1,1) - (2,2)와 같이해야합니다. 문제는 프로그래밍 방식으로 java/android에서 수행하는 방법입니다. 아래에서 이미 개발 한 코드를 첨부하고 있습니다.

/** Creating the containers for screen 
    * coordinates taken from geoPoints 
    */ 

    Point point1_screen = new Point(); 
    Point point2_screen = new Point(); 
    Point point3_screen = new Point(); 

    /* Project them from the map to screen */ 
    mapView.getProjection().toPixels(point1, point1_screen); 
    mapView.getProjection().toPixels(point2, point2_screen); 
mapView.getProjection().toPixels(point3, point3_screen); 

    int xA = point1_screen.x; 
    int yA = point1_screen.y; 

    int xB = point2_screen.x; 
    int yB = point2_screen.y; 

    int xC = point3_screen.x; 
    int yC = point3_screen.y; 

    int[] xPointsArray = new int[3]; 
    int[] yPointsArray = new int[3]; 

    xPointsArray[0] = xA; 
    xPointsArray[1] = xB; 
    xPointsArray[2] = xC; 

    yPointsArray[0] = yA; 
    yPointsArray[1] = yB; 
    yPointsArray[2] = yC; 

    Arrays.sort(xPointsArray); 

    int xMin = xPointsArray[0]; 
    int yMin = yPointsArray[0]; 

    int xMax = xPointsArray[xPointsArray.length-1]; 
    int yMax = xPointsArray[xPointsArray.length-1]; 

    int e = (xMax - xMin)/100;         // for ray calcultions 

    int width = mapView.getWidth(); 
    int height = mapView.getHeight(); 

    if(pPoint.x < xMin || pPoint.x > xMax || pPoint.y > yMin || pPoint.y < yMax) 
    { 

     DisplayInfoMessage(pPoint.x + " < " + xMin + " AND " + pPoint.x + " > " + xMax + " || " + pPoint.y + " < " + yMin + " AND " + pPoint.y + " > " + yMax); 
    // DisplayInfoMessage("Minimum is: "+ yPointsArray[0] + " and the maximum is: "+ yPointsArray[xPointsArray.length-1]); 

    } 
    else 
    { 
     GeoPoint start_point = new GeoPoint(xMin - e, pPoint.y); 
     Point start_point_container = new Point(); 
     mapView.getProjection().toPixels(start_point, start_point_container); 

      int a, b, c, tx, ty; 
      int d1, d2, hd; 
      int ix, iy; 
      float r; 
      // calculating vector for 1st line 

      tx = xB - xA; 
      ty = yB - yA; 

      // equation for 1st line 

      a = ty; 
      b = tx; 
      c = xA*a - yA*b; 

      // get distances from line for line 2 

      d1 = a*xB + b*yB + c; 
      d2 = a*pPoint.x + b*pPoint.y + c; 



      DisplayInfoMessage("You clicked inside the triangle!" + "TRIANGLE POINTS: A("+xA+","+yA+") B("+xB+","+yB+") C("+xC+","+yC+")"); 
    } 

pPoint는 사용자가 클릭 한 포인트의 좌표를 유지합니다. 나는 내 문제를 충분히 설명하기를 희망한다. 누군가 나에게 도움을 줄 수 있습니까? 감사!

답변

1

나는 안드로이드 개발자가 아니지만 android.graphics.drawable.shapes.Shape에는 java.awt.Shape에있는 메서드가 없습니다. 인용 한 article에 나와있는 것처럼 직접 테스트를 개발해야합니다. 또한 crossing/winding number 개의 알고리즘을 살펴볼 수도 있습니다.

하지만 어떻게 2 포인트를 뺄 수 있습니까?

벡터의 뺄셈은 잘 defined이고, 자바에서는 implemented입니다. 두 점을 벡터로하면 차이의 구성 요소는 점을 연결하는 선의 접선 (기울기)을 나타냅니다. article의 예는 다음 라인이 구현 : 도시 접근

//get tangent vector for line 1 
tx = v1x2 - v1x1; 
ty = v1y2 - v1y1; 

재단 Line and Segment Intersections에서 더 논의된다.

+0

힌트를 주셔서 감사합니다. trashgod - 도움이되었습니다. – Pavel

관련 문제