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


C++ ConvexPolygon::at方法代码示例

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


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

示例1: projectPolygon

void projectPolygon(Vector axis, ConvexPolygon polygon, qreal &min, qreal &max) 
{
    // To project a point on an axis use the dot product

    //qDebug() << "Projecting on "<< axis;
    qreal d = axis.dotProduct(polygon.at(0));
    min = d;
    max = d;
    for (int i = 0; i < polygon.size(); i++) 
    {
        d= polygon.at(i).dotProduct (axis);
        if (d < min) 
            min = d;
        else 
            if (d> max) max = d;
    //	qDebug() << "p="<<polygon.at(i)<<"  d="<<d<<"  (min, max)=("<<min<<","<<max<<")";	
    }
}
开发者ID:wcremeika,项目名称:thesis,代码行数:18,代码来源:geometry.cpp

示例2: polygonCollision

PolygonCollisionResult polygonCollision(ConvexPolygon polygonA, 
                              ConvexPolygon polygonB, Vector velocity) 
{
    PolygonCollisionResult result;
    result.intersect = true;
    result.willIntersect = true;

    int edgeCountA = polygonA.size();
    int edgeCountB = polygonB.size();
    qreal minIntervalDistance = 1000000000;
    QPointF translationAxis;
    QPointF edge;

/*
    qDebug() << "A: ";
    for (int k=0; k<edgeCountA;k++)
	qDebug() <<polygonA.at(k);
    qDebug() << "B: ";
    for (int k=0; k<edgeCountB;k++)
	qDebug() <<polygonB.at(k);
    qDebug() ;    
*/	
	
    // Loop through all the edges of both polygons
    for (int i=0;i<edgeCountA + edgeCountB;i++)
    {
        if (i< edgeCountA) 
	{
	    // Loop through polygon A
	    if (i<edgeCountA-1)
		edge = QPointF (
		    polygonA.at(i+1).x()-polygonA.at(i).x(), 
		    polygonA.at(i+1).y()-polygonA.at(i).y());
	    else	
		edge = QPointF (
		    polygonA.at(0).x()-polygonA.at(i).x(), 
		    polygonA.at(0).y()-polygonA.at(i).y());
        } else 
	{
	    // Loop through polygon B
	    if (i < edgeCountA +edgeCountB -1 )
		edge = QPointF (
		    polygonB.at(i-edgeCountA+1).x() - polygonB.at(i-edgeCountA).x(), 
		    polygonB.at(i-edgeCountA+1).y() - polygonB.at(i-edgeCountA).y());
	    else    
		edge = QPointF (
		    polygonB.at(0).x() - polygonB.at(i-edgeCountA).x(), 
		    polygonB.at(0).y() - polygonB.at(i-edgeCountA).y());
	}

        // ===== 1. Find if the polygons are currently intersecting =====

        // Find the axis perpendicular to the current edge

        Vector axis (-edge.y(), edge.x());
        axis.normalize();

        // Find the projection of the polygon on the current axis

        qreal minA = 0; qreal minB = 0; qreal maxA = 0; qreal maxB = 0;
        projectPolygon(axis, polygonA, minA, maxA);
        projectPolygon(axis, polygonB, minB, maxB);

        // Check if the polygon projections are currentlty intersecting

        qreal d = intervalDistance(minA, maxA, minB, maxB);
        if (d > 0) result.intersect = false;

       // ===== 2. Now find if the polygons *will* intersect =====


        // Project the velocity on the current axis

        qreal velocityProjection = axis.dotProduct(velocity);

        // Get the projection of polygon A during the movement

        if (velocityProjection < 0) 
            minA += velocityProjection;
        else 
            maxA += velocityProjection;

        // Do the same test as above for the new projection

        // d = intervalDistance(minA, maxA, minB, maxB);
        //if (d > 0) result.willIntersect = false;
	/*
	qDebug() <<"   ";
	qDebug() << "edge="<<edge<<"  ";
	qDebug() <<"axis="<<axis<<"  ";
	qDebug() <<"dA=("<<minA<<","<<maxA<<")  dB=("<<minB<<","<<maxB<<")";
	qDebug() <<"  d="<<d<<"   ";
	//qDebug() <<"minD="<<minIntervalDistance<<"  ";
	qDebug() <<"int="<<result.intersect<<"  ";
	//qDebug() <<"wint="<<result.willIntersect<<"  ";
	//qDebug() <<"velProj="<<velocityProjection<<"  ";
	qDebug() ;
	*/
    
        if (result.intersect )// || result.willIntersect) 
//.........这里部分代码省略.........
开发者ID:wcremeika,项目名称:thesis,代码行数:101,代码来源:geometry.cpp


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