當前位置: 首頁>>代碼示例>>Java>>正文


Java Vector2.crs方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.math.Vector2.crs方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2.crs方法的具體用法?Java Vector2.crs怎麽用?Java Vector2.crs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.math.Vector2的用法示例。


在下文中一共展示了Vector2.crs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getEdgesIntersection

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**
   * Finds the point were two Edges intersect.
   *
   * @param firstEdgeStartPoint  The first edge's starting point.
   * @param firstEdgeEndPoint    The first edge's ending point.
   * @param secondEdgeStartPoint The second edge's starting point.
   * @param secondEdgeEndPoint   The second edge's ending point.
   * @return The point were the two Edges intersect.
   */
  private static Vector2 getEdgesIntersection(Vector2 firstEdgeStartPoint,
                                              Vector2 firstEdgeEndPoint, Vector2 secondEdgeStartPoint,
                                              Vector2 secondEdgeEndPoint) {

      Vector2 firstDirectionPoint = new Vector2(firstEdgeStartPoint.x
              - firstEdgeEndPoint.x, firstEdgeStartPoint.y
              - firstEdgeEndPoint.y);
      Vector2 secondDirectionPoint = new Vector2(secondEdgeStartPoint.x
              - secondEdgeEndPoint.x, secondEdgeStartPoint.y
              - secondEdgeEndPoint.y);

/* Cross product of each edge */
      float crossFirstEdge = firstEdgeStartPoint.crs(firstEdgeEndPoint);
      float crossSecondEdge = secondEdgeStartPoint.crs(secondEdgeEndPoint);

      float inversedCrossDirection = 1 / firstDirectionPoint
              .crs(secondDirectionPoint);

      return new Vector2(
              (crossFirstEdge * secondDirectionPoint.x - crossSecondEdge
                      * firstDirectionPoint.x)
                      * inversedCrossDirection, (crossFirstEdge
              * secondDirectionPoint.y - crossSecondEdge
              * firstDirectionPoint.y)
              * inversedCrossDirection);
  }
 
開發者ID:AndreFCruz,項目名稱:feup-lpoo-armadillo,代碼行數:36,代碼來源:PolygonIntersector.java

示例2: computePolygonProperties

import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**
 * Computes the Polygon Properties of a given Polygon.
 *
 * @param polygon The polygon to be analyzed.
 * @return The Polygon Properties computed.
 */
public static PolygonProperties computePolygonProperties(Vector2[] polygon) {
    PolygonProperties polygonProperties = null;

    int count = polygon.length;

    if (count >= 3) {
        Vector2 centroid = new Vector2(0, 0);
        float area = 0;

        Vector2 refPoint = new Vector2(0, 0);
        float threeInverse = 1 / 3f;

        for (int i = 0; i < count; i++) {
            /*
 * Create a new vector to represent the reference point for
 * forming triangles. Then use refPoint, polygonVertex and
 * thirdTriangleVertex as vertices of a triangle.
 */
            refPoint.set(0, 0);
            Vector2 polygonVertex = polygon[i];
            Vector2 thirdTriangleVertex = i + 1 < count ? polygon[i + 1]
                    : polygon[0];

            Vector2 firstDirectionVector = polygonVertex.sub(refPoint);
            Vector2 secondDirectionVector = thirdTriangleVertex
                    .sub(refPoint);

            float triangleArea = firstDirectionVector
                    .crs(secondDirectionVector) / 2;
            area += triangleArea;

/* Area weighted centroid */
            centroid.add(refPoint.add(polygonVertex)
                    .add(thirdTriangleVertex)
                    .scl(triangleArea * threeInverse));
        }

        if (area > EPSILON) {
            centroid.scl(1 / area);
        } else {
            area = 0;
        }

        polygonProperties = new PolygonProperties(centroid, area);
    }

    return polygonProperties;
}
 
開發者ID:AndreFCruz,項目名稱:feup-lpoo-armadillo,代碼行數:55,代碼來源:PolygonIntersector.java


注:本文中的com.badlogic.gdx.math.Vector2.crs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。