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


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

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


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

示例1: setBuildingsInSightPoints

void WorldModel::setBuildingsInSightPoints()
{
    int extendedSightRange = maxSightRange * 2;
    LOG(Main, 2) << "num of roads: " << world->roads.size() << endl;
    for (int i = 0; i < (int) world->roads.size(); i++)
    {
        for (int j = 0; j < (int) world->roads[i]->getInnerPoints().size(); j++)
        {
            Point p = world->roads[i]->getInnerPoints()[j];
            vector<Building*> nearBuildings;
            //			vector<Point> nearPoints;
            //			vector<Point> upNearPoints;
            //			vector<Point> downNearPoints;
            LOG(Main, 2) << "road: " << i << " with id " << world->roads[i]->getId() << endl;
            for (int k = 0; k < (int) world->buildings.size(); k++)
            {
                if (distanceBetweenPoints(p, world->buildings[k]->getPos()) < extendedSightRange)
                {
                    nearBuildings.push_back(world->buildings[k]);
                    //					LOG(Main, 1) << "circle" << world->buildings[k]->getPos() << " 2000; ";
                }
            }
            //algorithm for sort near points
            //			for(int k = 0; k < (int)nearBuildings.size(); k++)
            //			{
            //				for(int l = 0; l < nearBuildings[k]->getShape().size(); l++)
            //				{
            //					Point tmp = nearBuildings[k]->getShape().getVertex(l);
            //					if(isLessEqual(p.getY(), tmp.getY()))
            //					{
            //						upNearPoints.push_back(tmp);
            //					}
            //					else
            //					{
            //						downNearPoints.push_back(tmp);
            //					}
            //				}
            //			}
            //			setComparePoint(p);
            //			sort(upNearPoints.begin(), upNearPoints.end(), Geometry::angleCompare);
            //			sort(downNearPoints.begin(), downNearPoints.end(), Geometry::angleCompare);
            //			for(int k = 0; k < (int)upNearPoints.size(); k++)
            //			{
            //				nearPoints.push_back(upNearPoints[k]);
            //			}
            //			for(int k = 0; k < (int)downNearPoints.size(); k++)
            //			{
            //				nearPoints.push_back(downNearPoints[k]);
            //			}
            //			LOG(Main, 2) << "after sort" << endl;
            //			if(nearPoints.size() == 0)
            //			{
            //				continue;
            //			}
            set<Building*> inSightBuildings;
            setColor(4);
            LOG(Main, 2) << Circle(p, maxSightRange) << ' ';
            LOG(Main, 2) << Circle(p, 500) << ' ';
            setColor(1);
            //			LOG(Main, 1) << "circle" << p << " " << extendedSightRange << "; ";
            //			for(int k = 1; k < (int)nearPoints.size(); k++)
            //			{
            //				LOG(Main, 1) << "line" << nearPoints[k - 1] << nearPoints[k] << "; ";
            //			}
            //			LOG(Main, 1) << "line" << nearPoints[0] << nearPoints.back() << "; ";
            //			for(int k = 0; k < (int)nearPoints.size(); k++)
            double dAngle = M_PI * 2 / rayCount;
            for (int k = 0; k < rayCount; k++)
            {
                //				int next = (k + 1) % nearPoints.size();
                //				Point mid = Segment(nearPoints[k], nearPoints[next]).getMiddlePoint();
                //				Segment s(p, mid);
                //				Vector ext = p.asVector() + s.asVector() * (extendedSightRange / s.getLength());
                //				s = Segment(p, ext.asPoint());
                double angle = k * dAngle;
                Segment s(p, (p.asVector() + Vector(sin(angle) * maxSightRange, cos(angle) * maxSightRange)).asPoint());
                LOG(Main, 2) << s << ' ';
                //				LOG(Main, 1) << "circle" << nearPoints[k] << " 200; ";
                double minDist = 1e10;
                Building* inSightBuilding = NULL;
                Segment minLine;
                for (int l = 0; l < (int) nearBuildings.size(); l++)
                {
                    for (int m = 0; m < nearBuildings[l]->getIDs().size(); m++)
                    {
                        if (nearBuildings[l]->getIDs()[m] == -1)
                        {
                            Segment edge = nearBuildings[l]->getShape().getSegment(m);
                            //							LOG(Main, 1) << "line" << edge.getFirstPoint() << edge.getSecondPoint() << "; ";
                            if (isIntersect(s, edge))
                            {
                                //								LOG(Main, 1) << "circle" << p << " " << maxSightRange << "; ";
                                //								LOG(Main, 1) << "circle" << p << " " << extendedSightRange << "; ";
                                //								LOG(Main, 1) << "line" << s.getFirstPoint() << s.getSecondPoint() << "; ";
                                //								LOG(Main, 1) << "line" << edge.getFirstPoint() << edge.getSecondPoint() << "; ";
                                Point intersect = getIntersectPoint(s.asLine(), edge.asLine());
                                //								LOG(Main, 1) << "circle" << intersect << " 200;" << endl;
                                if (isLess(distanceBetweenPoints(p, intersect), minDist))
                                {
                                    minDist = distanceBetweenPoints(p, intersect);
//.........这里部分代码省略.........
开发者ID:RGB-RSL,项目名称:rgb,代码行数:101,代码来源:WorldModel.cpp


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