-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tuto] added Wall class + CtcUnion binding
- Loading branch information
1 parent
009af9e
commit 21a277c
Showing
9 changed files
with
275 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* \file | ||
* Wall Python binding | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou, Benoît Desrochers | ||
* \copyright Copyright 2024 Codac Team | ||
* \license This program is distributed under the terms of | ||
* the GNU Lesser General Public License (LGPL). | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <pybind11/operators.h> | ||
#include <pybind11/functional.h> | ||
#include "codac_type_caster.h" | ||
|
||
#include "codac_Wall.h" | ||
// Generated file from Doxygen XML (doxygen2docstring.py): | ||
#include "codac_py_Wall_docs.h" | ||
|
||
using namespace std; | ||
using namespace codac; | ||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
|
||
void export_Wall(py::module& m) | ||
{ | ||
py::class_<Wall> wall(m, "Wall", WALL_MAIN); | ||
wall | ||
|
||
.def(py::init<const Vector&,const Vector&>(), "todo") | ||
.def("contains", &Wall::contains, "todo", "p"_a) | ||
.def(py::self & py::self) | ||
.def_readwrite("c1", &Wall::c1) | ||
.def_readwrite("c2", &Wall::c2) | ||
; | ||
|
||
m.def("shorter_dist_to_walls", &shorter_dist_to_walls, "todo", "v_walls"_a, "p"_a, "bearing"_a); | ||
m.def("shorter_contact_to_walls", &shorter_contact_to_walls, "todo", "v_walls"_a, "p"_a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Wall class | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou | ||
* \copyright Copyright 2024 Codac Team | ||
* \license This program is distributed under the terms of | ||
* the GNU Lesser General Public License (LGPL). | ||
*/ | ||
|
||
#include <iostream> | ||
#include "codac_Wall.h" | ||
#include "codac_predef_values.h" | ||
|
||
using namespace std; | ||
using namespace ibex; | ||
|
||
namespace codac | ||
{ | ||
Wall::Wall(const Vector& c1_, const Vector& c2_) : c1(c1_), c2(c2_) | ||
{ | ||
} | ||
|
||
bool Wall::contains(const Vector& p) const | ||
{ | ||
Vector ab { c2[0]-c1[0], c2[1]-c1[1] }; | ||
Vector ac { p[0]-c1[0], p[1]-c1[1] }; | ||
|
||
double dp_AB = ab[0]*ab[0] + ab[1]*ab[1]; | ||
double dp_AC = ab[0]*ac[0] + ab[1]*ac[1]; | ||
return Interval(0.,dp_AB).contains(dp_AC); | ||
} | ||
|
||
Vector operator&(const Wall& w1, const Wall& w2) | ||
{ | ||
const double& x1 = w1.c1[0]; const double& x2 = w1.c2[0]; | ||
const double& x3 = w2.c1[0]; const double& x4 = w2.c2[0]; | ||
|
||
const double& y1 = w1.c1[1]; const double& y2 = w1.c2[1]; | ||
const double& y3 = w2.c1[1]; const double& y4 = w2.c2[1]; | ||
|
||
return { | ||
((x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)), | ||
((x1*y2-y1*x2)*(y3-y4)-(y1-y2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)) | ||
}; | ||
} | ||
|
||
double shorter_dist_to_walls(const std::vector<Wall>& v_walls, const Vector& p, double bearing) | ||
{ | ||
Wall w0 { p, { p[0]+999999.*cos(bearing), p[1]+999999.*sin(bearing) }}; | ||
double min_dist = oo; | ||
|
||
for(const auto& wi : v_walls) | ||
{ | ||
Vector pi = w0 & wi; | ||
if(!wi.contains(pi) || !w0.contains(pi)) | ||
continue; | ||
double dist = pow(p[0]-pi[0],2) + pow(p[1]-pi[1],2); | ||
min_dist = dist < min_dist ? dist : min_dist; | ||
} | ||
|
||
return sqrt(min_dist); | ||
} | ||
|
||
Vector shorter_contact_to_walls(const std::vector<Wall>& v_walls, const Vector& p) | ||
{ | ||
double min_dist = oo; | ||
double bearing; | ||
|
||
for(double a = 0. ; a < 2.*M_PI ; a+=0.1) | ||
{ | ||
double dist = shorter_dist_to_walls(v_walls, p, a); | ||
if(dist < min_dist) | ||
{ | ||
min_dist = dist; | ||
bearing = a; | ||
} | ||
} | ||
|
||
return { min_dist, bearing }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Beacon class | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou | ||
* \copyright Copyright 2024 Codac Team | ||
* \license This program is distributed under the terms of | ||
* the GNU Lesser General Public License (LGPL). | ||
*/ | ||
|
||
#ifndef __CODAC_WALL_H__ | ||
#define __CODAC_WALL_H__ | ||
|
||
#include "codac_Vector.h" | ||
#include "codac_IntervalVector.h" | ||
|
||
namespace codac | ||
{ | ||
class Wall | ||
{ | ||
public: | ||
|
||
Wall(const Vector& c1, const Vector& c2); | ||
bool contains(const Vector& p) const; | ||
|
||
//protected: | ||
|
||
Vector c1, c2; | ||
}; | ||
|
||
Vector operator&(const Wall& w1, const Wall& w2); | ||
|
||
double shorter_dist_to_walls(const std::vector<Wall>& v_walls, const Vector& p, double bearing); | ||
Vector shorter_contact_to_walls(const std::vector<Wall>& v_walls, const Vector& p); | ||
} | ||
|
||
#endif |