当前位置: 首页>>代码示例>>Java>>正文


Java Vector3D.getNormSq方法代码示例

本文整理汇总了Java中org.apache.commons.math3.geometry.euclidean.threed.Vector3D.getNormSq方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3D.getNormSq方法的具体用法?Java Vector3D.getNormSq怎么用?Java Vector3D.getNormSq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.geometry.euclidean.threed.Vector3D的用法示例。


在下文中一共展示了Vector3D.getNormSq方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intersect

import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; //导入方法依赖的package包/类
/**
 * Determine point of intersection with another arc
 *
 * @return point of intersection, or null if there is no unique intersection
 */
public GeoPoint intersect(GeoArc arcB) {
    GeoArc arcA = this;

    // If either arc is zero-length, no solution exists
    if (arcA.length() < TOLERANCE) return null;
    if (arcB.length() < TOLERANCE) return null;

    // Convert points to cartesian
    Vector3D p1 = arcA.pointA.toCartesian();
    Vector3D p2 = arcA.pointB.toCartesian();
    Vector3D p3 = arcB.pointA.toCartesian();
    Vector3D p4 = arcB.pointB.toCartesian();

    // Determine planes on which arcs lie
    Vector3D vA = Vector3D.crossProduct(p1, p2);
    Vector3D vB = Vector3D.crossProduct(p3, p4);

    // Zero vector indicates antipodal points, which have no solution
    if (vA.getNormSq() <= 0) return null;
    if (vB.getNormSq() <= 0) return null;

    // Determine line where planes intersect (which lies between points of circle intersection)
    Vector3D v = Vector3D.crossProduct(vA.normalize(), vB.normalize());
    double vLenSq = v.getNormSq();

    // Zero vector indicates arcs on the same plane, which would have infinite solutions
    if (vLenSq <= 0) return null;

    // Normalize to unit length, which will result in a point on the sphere surface
    v = v.scalarMultiply(1 / Math.sqrt(vLenSq));

    // Convert the intersection points from cartesian to GeoPoint
    GeoPoint s1 = new GeoPoint(v);
    GeoPoint s2 = new GeoPoint(v.negate());

    // If one of the points lies on both arcs, it is the solution
    if (arcA.contains(s1) && arcB.contains(s1)) {
        return s1;
    }
    if (arcA.contains(s2) && arcB.contains(s2)) {
        return s2;
    }

    return null;
}
 
开发者ID:cadouthat,项目名称:geo-java,代码行数:51,代码来源:GeoArc.java


注:本文中的org.apache.commons.math3.geometry.euclidean.threed.Vector3D.getNormSq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。