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


C++ Segment::FormNormal方法代码示例

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


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

示例1: ConnectSegmentNeighbors

void Slice::ConnectSegmentNeighbors()
{
	unsigned int s;
    unsigned int potential;
    unsigned int s2;
	double potentialangle;
	double potentialDist;
	double minDist = 10000.0;

	Segment* thisSeg = NULL;
	Segment* thatSeg = NULL;
    QVector2D* thisPoint = NULL;

    QVector2D* thatPoint = NULL;

    std::vector<Segment*> sameXStripSegs;
    std::vector<Segment*> potentialLeadSegs;

    Segment* finalLeadSeg = NULL;

	for(s = 0; s < segmentList.size(); s++)//compare from every segment
	{
		thisSeg = segmentList[s];
		thisPoint = &thisSeg->p2;//compare from the 2nd point on "this" segment

		if(thisSeg->leadingSeg)//no need to add a connection if there already is one!
			continue;
		
		potentialLeadSegs.clear();//clear out the potentials list
		

        GetSegmentsAroundX(sameXStripSegs, thisPoint->x());


        //////////////////////////////////////
        for(s2 = 0; s2 < sameXStripSegs.size(); s2++)//to every other segment in ring
		{
			//make sure its not the same segment
			if(s == s2)
			{continue;}
			
            thatSeg = sameXStripSegs[s2];
			if(thatSeg->trailingSeg)//already connected to a trailing segment...
				continue;
			
			thatPoint = &thatSeg->p1;//to the first point of "that" segment
            if(IsZero(Distance2D(*thisPoint, *thatPoint),0.03))//they are close enough to each other
            {
				potentialLeadSegs.push_back(thatSeg);
            }
		}
        //////////////////////////////////////

		//sort through and pick from the potential pile
		//we want to pick a segment with the sharpest change in direction!
		//
		//
		//1>>>>>>>>>A>>>>>>>>2 1>>>>>>>>B>>>>>>>>>2
		//                    ^
		//             large delta angle/ Right Wieghted
		minDist = 100000.0;
		finalLeadSeg = NULL;
		potentialangle = 0.0;
		for(potential = 0; potential < potentialLeadSegs.size(); potential++)
		{
			thatSeg = potentialLeadSegs[potential];
			//potentialDot = (thisSeg->normal.x() * thatSeg->normal.x()) + (thisSeg->normal.y() * thatSeg->normal.y()); //gives a number indicating how sharp the angle is, -1 is the sharpest (-1,1)
			//potentialCross = (thisSeg->normal.x() * thatSeg->normal.y()) - (thisSeg->normal.y() * thatSeg->normal.x());//gives a number indicating a right or left turn. (uphill is positive), (downhill is negative) (-1,1)
			potentialDist = Distance2D(thisSeg->p2, thatSeg->p1);
			
			if(potentialDist < minDist)
			{
				minDist = potentialDist;
				finalLeadSeg = potentialLeadSegs[potential];
			}
			
		}
		if(finalLeadSeg)
		{
			thisSeg->leadingSeg = finalLeadSeg;
			finalLeadSeg->trailingSeg = thisSeg;

			thisSeg->p2 = finalLeadSeg->p1;
			thisSeg->FormNormal();
		}
	}
}
开发者ID:SHINOTECH,项目名称:B9Creator-QT5.X,代码行数:87,代码来源:slice.cpp

示例2: CorrectDoubleBacks

int Loop::CorrectDoubleBacks()
{
    int numDoubleBacks = 0;
    unsigned int s;

    double normalsDot;

    std::vector<Segment*> keepList;
    Segment* thisSeg;
    Segment* thatSeg;
    if(segListp.size() <= 3)
    {
        return 0;
    }

    //first we should find some double backs....
    for(s = 0; s < segListp.size(); s++)
    {
        if(segListp[s]->chucked)
        {
            continue;//if segments already have been thrown
        }

        thisSeg = segListp[s];
        thatSeg = thisSeg->leadingSeg;

        //get dot product
        normalsDot = (thisSeg->normal.x() * thatSeg->normal.x()) + (thisSeg->normal.y() * thatSeg->normal.y());

        if(normalsDot < -0.999)//doubleback (1-Dot)*2*180 = Degrees freedom,  current(-0.999) = 0.36 degrees
        {
            numDoubleBacks++;
            //compute length of thisSeg and thatSeg
            //thislength = Distance2D(thisSeg->p1, thisSeg->p2);
            //thatlength = Distance2D(thatSeg->p1, thatSeg->p2);


            thisSeg->p2 = thatSeg->p2;
            thisSeg->FormNormal();
            thisSeg->leadingSeg = thatSeg->leadingSeg;
            thatSeg->leadingSeg->trailingSeg = thisSeg;
            thatSeg->leadingSeg = NULL;
            thatSeg->trailingSeg = NULL;
            thatSeg->chucked = true;

            s = 0;//start from beggining of list again
        }
    }

    if(numDoubleBacks > 0)
    {
        for(s = 0; s < segListp.size(); s++)
        {
            if(segListp[s]->chucked)
            {
                segListp[s]->chucked = false;
            }
            else
            {
                keepList.push_back(segListp[s]);
            }
        }
        segListp.clear();
        segListp = keepList;
        numSegs = segListp.size();
    }

    return numDoubleBacks;
}
开发者ID:sjw107273131,项目名称:B9Creator,代码行数:69,代码来源:loop.cpp


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