Exposed some vector functions to the python api

This commit is contained in:
Guillermo 2021-08-06 10:56:41 +02:00 committed by Axel1092
parent 74ea12357d
commit fee6a749f5
3 changed files with 100 additions and 1 deletions

View File

@ -1,3 +1,8 @@
## Latest
* Added API functions to 3D vectors: `squared_length`, `length`, `make_unit_vector`, `dot`, `dot_2d`, `distance`, `distance_2d`, `distance_squared`, `distance_squared_2d`, `get_vector_angle`
* Added API functions to 2D vectors: `squared_length`, `length`, `make_unit_vector`
## CARLA 0.9.12
* Changed the resolution of the cached map in Traffic Manager from 0.1 to 5 meters

View File

@ -2390,6 +2390,15 @@ Y-axis value.
- **Parameters:**
- `x` (_float_)
- `y` (_float_)
- <a name="carla.Vector2D.squared_length"></a>**<font color="#7fb800">squared_length</font>**(<font color="#00a6ed">**self**</font>)
Computes the squared length of the vector.
- **Return:** _float_
- <a name="carla.Vector2D.length"></a>**<font color="#7fb800">length</font>**(<font color="#00a6ed">**self**</font>)
Computes the length of the vector.
- **Return:** _float_
- <a name="carla.Vector2D.make_unit_vector"></a>**<font color="#7fb800">make_unit_vector</font>**(<font color="#00a6ed">**self**</font>)
Returns a vector with the same direction and unitary length.
- **Return:** _[carla.Vector2D](#carla.Vector2D)_
##### Dunder methods
- <a name="carla.Vector2D.__add__"></a>**<font color="#7fb800">\__add__</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**other**=[carla.Vector2D](#carla.Vector2D)</font>)
@ -2425,6 +2434,50 @@ Z-axis value.
- `x` (_float_)
- `y` (_float_)
- `z` (_float_)
- <a name="carla.Vector3D.length"></a>**<font color="#7fb800">length</font>**(<font color="#00a6ed">**self**</font>)
Computes the length of the vector.
- **Return:** _float_
- <a name="carla.Vector3D.squared_length"></a>**<font color="#7fb800">squared_length</font>**(<font color="#00a6ed">**self**</font>)
Computes the squared length of the vector.
- **Return:** _float_
- <a name="carla.Vector3D.make_unit_vector"></a>**<font color="#7fb800">make_unit_vector</font>**(<font color="#00a6ed">**self**</font>)
Returns a vector with the same direction and unitary length.
- **Return:** _[carla.Vector3D](#carla.Vector3D)_
- <a name="carla.Vector3D.dot"></a>**<font color="#7fb800">dot</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**vector**</font>)
Computes the dot product between two vectors.
- **Parameters:**
- `vector` (_[carla.Vector3D](#carla.Vector3D)_)
- **Return:** _float_
- <a name="carla.Vector3D.distance"></a>**<font color="#7fb800">distance</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**vector**</font>)
Computes the distance between two vectors.
- **Parameters:**
- `vector` (_[carla.Vector3D](#carla.Vector3D)_)
- **Return:** _float_
- <a name="carla.Vector3D.distance_squared"></a>**<font color="#7fb800">distance_squared</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**vector**</font>)
Computes the squared distance between two vectors.
- **Parameters:**
- `vector` (_[carla.Vector3D](#carla.Vector3D)_)
- **Return:** _float_
- <a name="carla.Vector3D.dot_2d"></a>**<font color="#7fb800">dot_2d</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**vector**</font>)
Computes the 2-dimensional dot product between two vectors.
- **Parameters:**
- `vector` (_[carla.Vector3D](#carla.Vector3D)_)
- **Return:** _float_
- <a name="carla.Vector3D.distance_2d"></a>**<font color="#7fb800">distance_2d</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**vector**</font>)
Computes the 2-dimensional distance between two vectors.
- **Parameters:**
- `vector` (_[carla.Vector3D](#carla.Vector3D)_)
- **Return:** _float_
- <a name="carla.Vector3D.distance_squared_2d"></a>**<font color="#7fb800">distance_squared_2d</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**vector**</font>)
Computes the 2-dimensional squared distance between two vectors.
- **Parameters:**
- `vector` (_[carla.Vector3D](#carla.Vector3D)_)
- **Return:** _float_
- <a name="carla.Vector3D.get_vector_angle"></a>**<font color="#7fb800">get_vector_angle</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**vector**</font>)
Computes the angle between two vectors.
- **Parameters:**
- `vector` (_[carla.Vector3D](#carla.Vector3D)_)
- **Return:** _float_
##### Dunder methods
- <a name="carla.Vector3D.__abs__"></a>**<font color="#7fb800">\__abs__</font>**(<font color="#00a6ed">**self**</font>)
@ -4149,4 +4202,4 @@ for (let i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click",function(){ButtonAction(buttons[i].id);},true);
}
window.onresize = WindowResize;
</script>
</script>

View File

@ -103,6 +103,34 @@ static auto GetInverseTransformMatrix(const carla::geom::Transform &self) {
return BuildMatrix(self.GetInverseMatrix());
}
static auto Dot(const carla::geom::Vector3D &self, const carla::geom::Vector3D &other) {
return carla::geom::Math::Dot(self, other);
}
static auto Distance(const carla::geom::Vector3D &self, const carla::geom::Vector3D &other) {
return carla::geom::Math::Distance(self, other);
}
static auto DistanceSquared(const carla::geom::Vector3D &self, const carla::geom::Vector3D &other) {
return carla::geom::Math::DistanceSquared(self, other);
}
static auto Dot2D(const carla::geom::Vector3D &self, const carla::geom::Vector3D &other) {
return carla::geom::Math::Dot2D(self, other);
}
static auto Distance2D(const carla::geom::Vector3D &self, const carla::geom::Vector3D &other) {
return carla::geom::Math::Distance2D(self, other);
}
static auto DistanceSquared2D(const carla::geom::Vector3D &self, const carla::geom::Vector3D &other) {
return carla::geom::Math::DistanceSquared2D(self, other);
}
static auto GetVectorAngle(const carla::geom::Vector3D &self, const carla::geom::Vector3D &other) {
return carla::geom::Math::GetVectorAngle(self, other);
}
void export_geom() {
using namespace boost::python;
namespace cg = carla::geom;
@ -115,6 +143,9 @@ void export_geom() {
.def(init<float, float>((arg("x")=0.0f, arg("y")=0.0f)))
.def_readwrite("x", &cg::Vector2D::x)
.def_readwrite("y", &cg::Vector2D::y)
.def("squared_length", &cg::Vector2D::SquaredLength)
.def("length", &cg::Vector2D::Length)
.def("make_unit_vector", &cg::Vector2D::MakeUnitVector)
.def("__eq__", &cg::Vector2D::operator==)
.def("__ne__", &cg::Vector2D::operator!=)
.def(self += self)
@ -139,6 +170,16 @@ void export_geom() {
.def_readwrite("x", &cg::Vector3D::x)
.def_readwrite("y", &cg::Vector3D::y)
.def_readwrite("z", &cg::Vector3D::z)
.def("length", &cg::Vector3D::Length)
.def("squared_length", &cg::Vector3D::SquaredLength)
.def("make_unit_vector", &cg::Vector3D::MakeUnitVector)
.def("dot", &Dot, (arg("vector")))
.def("dot_2d", &Dot2D, (arg("vector")))
.def("distance", &Distance, (arg("vector")))
.def("distance_2d", &Distance2D, (arg("vector")))
.def("distance_squared", &DistanceSquared, (arg("vector")))
.def("distance_squared_2d", &DistanceSquared2D, (arg("vector")))
.def("get_vector_angle", &GetVectorAngle, (arg("vector")))
.def("__eq__", &cg::Vector3D::operator==)
.def("__ne__", &cg::Vector3D::operator!=)
.def("__abs__", &cg::Vector3D::Abs)