1 Star 1 Fork 3

陈狗翔 / RRT-path-planning

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
RRTstar.cpp 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
陈狗翔 提交于 2018-01-24 21:35 . RRT path planning
#include "RRTstar.h"
#include <time.h>
int RRTstar::getCost(tree_node * t)
{
if (t->father == NULL)
{
return 0;
}
else
{
return (getDistance(t->pos,t->father->pos)+ getCost(t->father));
}
}
void RRTstar::createTree()
{
using namespace std;
using namespace cv;
int i=0;
srand(time(0));
bool findpath=true;
std::vector<tree_node * > isline;
while(i++ <K && findpath)
{
isline.clear();
int x=rand()%sizeX;
int y=rand()%sizeY;
while(map[x][y] != 0)
{
x=rand()%sizeX;
y=rand()%sizeY;
}
point temp(x,y);
int flag=-1;
int dist=999999;
point p=start;
for (int i=0;i<graph.size();i++)
{
int d=getDistance(temp,graph[i]->pos);
if (d< dist)
{
dist=d;
flag=i;
}
}
p.x=graph[flag]->pos.x;
p.y=graph[flag]->pos.y;
int num=9999;
int pos=0;
while (! if_line(p,temp) && num >minstep)
{
num=line.size();
pos = rand()%num;
num=pos;
temp=line[pos];
}
num=line.size();
if (num < minstep || ! if_line(p,temp))
{
continue;
}
for (int i=0;i<num;i++)
{
circle( img,Point(line[i].x,line[i].y), 0.1, Scalar(0,10,255), 0.1, 1, 0 );
}
int cost = getCost(graph[flag]);
if ( (cost+getDistance(temp,p)+getDistance(temp,goal)) < 1.1*(cost + getDistance(graph[flag]->pos,goal)) )
{
tree_node * t=new tree_node(temp,graph[flag]);
graph.push_back(t);
if ((getDistance(temp,goal) < minstep+10 ) && if_line(temp,goal))
{
path.push_back(goal);
tree_node * temp_ = graph[graph.size()-1];
circle( img,Point(start.x,start.y), 3, Scalar(0,0,0), 3, 1, 0 );
circle( img,Point(goal.x,goal.y), 3, Scalar(0,0,0), 3, 1, 0 );
/* for (int i=0;i<graph.size();i++)
{
if (temp_ != NULL)
{
path.push_back(temp_->pos);
temp_=temp_->father;
}
}*/
for (;temp_!=NULL;temp_=temp_->father)
{
path.push_back(temp_->pos);
}
findpath=false;
}
}
}
}
C++
1
https://gitee.com/ChenGouXiang/RRT-path-planning.git
git@gitee.com:ChenGouXiang/RRT-path-planning.git
ChenGouXiang
RRT-path-planning
RRT-path-planning
master

搜索帮助