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


C++ Vec3d::length2方法代码示例

本文整理汇总了C++中osg::Vec3d::length2方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3d::length2方法的具体用法?C++ Vec3d::length2怎么用?C++ Vec3d::length2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osg::Vec3d的用法示例。


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

示例1: CalcPolysIntersectSAT

bool CalcPolysIntersectSAT(std::vector<osg::Vec3d> const &polyA_list_vx,
                           std::vector<osg::Vec3d> const &polyA_list_face_norms,
                           std::vector<osg::Vec3d> const &polyA_list_edges,
                           std::vector<osg::Vec3d> const &polyB_list_vx,
                           std::vector<osg::Vec3d> const &polyB_list_face_norms,
                           std::vector<osg::Vec3d> const &polyB_list_edges)
{
    // Test the faces of polyA
    for(auto const &polyA_face_norm : polyA_list_face_norms)
    {
        if(!ProjectionIntervalsOverlap(polyA_face_norm,
                                       polyA_list_vx,
                                       polyB_list_vx)) {
            return false;
        }
    }

    // Test the faces of polyB
    for(auto const &polyB_face_norm : polyB_list_face_norms)
    {
        if(!ProjectionIntervalsOverlap(polyB_face_norm,
                                       polyA_list_vx,
                                       polyB_list_vx)) {
            return false;
        }
    }

    // Test the cross product of the edges of polyA and polyB
    for(auto const &polyA_edge : polyA_list_edges) {
        for(auto const &polyB_edge : polyB_list_edges)
        {
            osg::Vec3d const axis = polyA_edge^polyB_edge;

            // Edge may be invalid -- need to handle
            // this case better
            if(axis.length2() < 1E-5) {
                continue;
            }

            if(!ProjectionIntervalsOverlap(axis,
                                           polyA_list_vx,
                                           polyB_list_vx)) {
                return false;
            }
        }
    }

//    for(auto const &interval : list_polyA_intervals) {
//        std::cout << "###: min: " << interval.first
//                  << "max: " << interval.second << std::endl;
//    }

    // Intersection
    return true;
}
开发者ID:lanixXx,项目名称:scratch,代码行数:55,代码来源:sat.cpp

示例2:

bool
GeoMath::isPointVisible(const osg::Vec3d& eye,
                        const osg::Vec3d& target,
                        double            R)
{
    double r2 = R*R;

    // same quadrant:
    if ( eye * target >= 0.0 )
    {
        double d2 = eye.length2();
        double horiz2 = d2 - r2;
        double dist2 = (target-eye).length2();
        if ( dist2 < horiz2 )
        {
            return true;
        }
    }

    // different quadrants:
    else
    {
        // there's a horizon between them; now see if the thing is visible.
        // find the triangle formed by the viewpoint, the target point, and 
        // the center of the earth.
        double a = (target-eye).length();
        double b = target.length();
        double c = eye.length();

        // Heron's formula for triangle area:
        double s = 0.5*(a+b+c);
        double area = 0.25*sqrt( s*(s-a)*(s-b)*(s-c) );

        // Get the triangle's height:
        double h = (2*area)/a;

        if ( h >= R )
        {
            return true;
        }
    }

    return false;
}
开发者ID:aroth-fastprotect,项目名称:osgearth,代码行数:44,代码来源:GeoMath.cpp

示例3: CriticalPointsLineCircle

// From WildMagic, (c) Geometric Tools LLC
// See Eberly, Distance between Line and Circle
void CriticalPointsLineCircle(Circle const &c,
                              osg::Vec3d const &line_p, // line point
                              osg::Vec3d const &line_d, // line dirn
                              osg::Vec3d &min,
                              osg::Vec3d &max)
{
    osg::Vec3d diff = line_p - c.center;
    double diffSqrLen = diff.length2();
    double MdM = line_d.length2();
    double DdM = diff*line_d;
    double NdM = c.normal*line_d;
    double DdN = diff*c.normal;

    double a0 = DdM;
    double a1 = MdM;
    double b0 = DdM - NdM*DdN;
    double b1 = MdM - NdM*NdM;
    double c0 = diffSqrLen - DdN*DdN;
    double c1 = b0;
    double c2 = b1;
    double rsqr = c.radius*c.radius;

    double a0sqr = a0*a0;
    double a1sqr = a1*a1;
    double twoA0A1 = 2.0*a0*a1;
    double b0sqr = b0*b0;
    double b1Sqr = b1*b1;
    double twoB0B1 = 2.0*b0*b1;
    double twoC1 = 2.0*c1;

    // The minimum point B+t*M occurs when t is a root of the quartic
    // equation whose coefficients are defined below.

    // I think index specifies polynomial degree
    // ie. poly[3] = coefficient for x^3

    Polynomial1<Real> poly(4);
    poly[0] = a0sqr*c0 - b0sqr*rsqr;
    poly[1] = twoA0A1*c0 + a0sqr*twoC1 - twoB0B1*rsqr;
    poly[2] = a1sqr*c0 + twoA0A1*twoC1 + a0sqr*c2 - b1Sqr*rsqr;
    poly[3] = a1sqr*twoC1 + twoA0A1*c2;
    poly[4] = a1sqr*c2;

    PolynomialRoots<Real> polyroots(Math<Real>::ZERO_TOLERANCE);
    polyroots.FindB(poly, 6);
    int count = polyroots.GetCount();
    const Real* roots = polyroots.GetRoots();

    Real minSqrDist = Math<Real>::MAX_REAL;
    for (int i = 0; i < count; ++i)
    {
        // Compute distance from P(t) to circle.
        Vector3<Real> P = mLine->Origin + roots[i]*mLine->Direction;
        DistPoint3Circle3<Real> query(P, *mCircle);
        Real sqrDist = query.GetSquared();
        if (sqrDist < minSqrDist)
        {
            minSqrDist = sqrDist;
            mClosestPoint0 = query.GetClosestPoint0();
            mClosestPoint1 = query.GetClosestPoint1();
        }
    }

    return minSqrDist;
}
开发者ID:lanixXx,项目名称:scratch,代码行数:67,代码来源:vx_circletest.cpp


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