Document and refactor geom code.
- Doxygenate headers. - Rename to bring methods and functions in line with everything else.
This commit is contained in:
@@ -1,33 +1,32 @@
|
||||
///
|
||||
/// \file include/scmp/geom/Coord2D.h
|
||||
/// \author K. Isom <kyle@imap.cc>
|
||||
/// \date 2017-06-05
|
||||
/// \brief 2D point and polar coordinate systems.
|
||||
///
|
||||
/// Copyright 2023 K. Isom <kyle@imap.cc>
|
||||
///
|
||||
/// Permission to use, copy, modify, and/or distribute this software for
|
||||
/// any purpose with or without fee is hereby granted, provided that
|
||||
/// the above copyright notice and this permission notice appear in all /// copies.
|
||||
///
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
/// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
/// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
||||
/// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
/// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
/// PERFORMANCE OF THIS SOFTWARE.
|
||||
///
|
||||
|
||||
//
|
||||
// Project: scccl
|
||||
// File: src/math/geom2d.cpp
|
||||
// Author: Kyle Isom
|
||||
// Date: 2017-06-05
|
||||
// Namespace: math::geom
|
||||
//
|
||||
// geom2d.cpp contains the implementation of 2D geometry in the math::geom
|
||||
// namespace.
|
||||
//
|
||||
// Copyright 2017 Kyle Isom <kyle@imap.cc>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <scmp/Math.h>
|
||||
#include <scmp/geom/Coord2D.h>
|
||||
#include <scmp/geom/Orientation.h>
|
||||
#include <scmp/geom/Vector.h>
|
||||
|
||||
|
||||
@@ -61,21 +60,21 @@ Point2D::Point2D(const Polar2D &pol)
|
||||
int
|
||||
Point2D::X() const
|
||||
{
|
||||
return this->at(0);
|
||||
return this->At(0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Point2D::X(int _x)
|
||||
{
|
||||
this->Set(0, _x);
|
||||
this->Set(BasisX, _x);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Point2D::Y() const
|
||||
{
|
||||
return this->at(1);
|
||||
return this->At(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +164,7 @@ Polar2D::Polar2D(const Point2D &pt)
|
||||
double
|
||||
Polar2D::R() const
|
||||
{
|
||||
return this->at(0);
|
||||
return this->At(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +178,7 @@ Polar2D::R(const double _r)
|
||||
double
|
||||
Polar2D::Theta() const
|
||||
{
|
||||
return this->at(1);
|
||||
return this->At(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ namespace scmp {
|
||||
namespace basic {
|
||||
|
||||
|
||||
scmp::geom::Vector2d
|
||||
scmp::geom::Vector2D
|
||||
Acceleration(double speed, double heading)
|
||||
{
|
||||
auto dx = std::cos(heading) * speed;
|
||||
auto dy = std::sin(heading) * speed;
|
||||
|
||||
return scmp::geom::Vector2d({dx, dy});
|
||||
return scmp::geom::Vector2D({dx, dy});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,31 +7,31 @@ namespace geom {
|
||||
|
||||
|
||||
float
|
||||
Heading2f(Vector2f vec)
|
||||
Heading2F(Vector2F vec)
|
||||
{
|
||||
return vec.angle(Basis2f[Basis_x]);
|
||||
return vec.Angle(Basis2F[BasisX]);
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
Heading3f(Vector3f vec)
|
||||
Heading3f(Vector3F vec)
|
||||
{
|
||||
Vector2f vec2f {vec[0], vec[1]};
|
||||
return Heading2f(vec2f);
|
||||
Vector2F vec2f {vec[0], vec[1]};
|
||||
return Heading2F(vec2f);
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
Heading2d(Vector2d vec)
|
||||
Heading2d(Vector2D vec)
|
||||
{
|
||||
return vec.angle(Basis2d[Basis_x]);
|
||||
return vec.Angle(Basis2D[BasisX]);
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
Heading3d(Vector3d vec)
|
||||
Heading3d(Vector3D vec)
|
||||
{
|
||||
Vector2d vec2d {vec[0], vec[1]};
|
||||
Vector2D vec2d {vec[0], vec[1]};
|
||||
return Heading2d(vec2d);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,23 +8,23 @@ namespace geom {
|
||||
|
||||
|
||||
Quaternionf
|
||||
quaternionf(Vector3f axis, float angle)
|
||||
MakeQuaternion(Vector3F axis, float angle)
|
||||
{
|
||||
return Quaternionf(axis.unitVector() * std::sin(angle / 2.0),
|
||||
return Quaternionf(axis.UnitVector() * std::sin(angle / 2.0),
|
||||
std::cos(angle / 2.0));
|
||||
}
|
||||
|
||||
|
||||
Quaterniond
|
||||
quaterniond(Vector3d axis, double angle)
|
||||
MakeQuaternion(Vector3D axis, double angle)
|
||||
{
|
||||
return Quaterniond(axis.unitVector() * std::sin(angle / 2.0),
|
||||
return Quaterniond(axis.UnitVector() * std::sin(angle / 2.0),
|
||||
std::cos(angle / 2.0));
|
||||
}
|
||||
|
||||
|
||||
Quaternionf
|
||||
quaternionf_from_euler(Vector3f euler)
|
||||
QuaternionFromEuler(Vector3F euler)
|
||||
{
|
||||
float x, y, z, w;
|
||||
euler = euler / 2.0;
|
||||
@@ -41,12 +41,12 @@ quaternionf_from_euler(Vector3f euler)
|
||||
z = (cos_yaw * cos_pitch * sin_roll) + (sin_yaw * sin_pitch * cos_roll);
|
||||
w = (cos_yaw * cos_pitch * cos_roll) - (sin_yaw * sin_pitch * sin_roll);
|
||||
|
||||
return Quaternionf(Vector4f{w, x, y, z});
|
||||
return Quaternionf(Vector4F{w, x, y, z});
|
||||
}
|
||||
|
||||
|
||||
Quaterniond
|
||||
quaterniond_from_euler(Vector3d euler)
|
||||
QuaternionFromEuler(Vector3D euler)
|
||||
{
|
||||
double x, y, z, w;
|
||||
euler = euler / 2.0;
|
||||
@@ -63,21 +63,21 @@ quaterniond_from_euler(Vector3d euler)
|
||||
z = (cos_yaw * cos_pitch * sin_roll) + (sin_yaw * sin_pitch * cos_roll);
|
||||
w = (cos_yaw * cos_pitch * cos_roll) - (sin_yaw * sin_pitch * sin_roll);
|
||||
|
||||
return Quaterniond(Vector4d{w, x, y, z});
|
||||
return Quaterniond(Vector4D{w, x, y, z});
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Quaternion_SelfTest()
|
||||
QuaternionSelfTest()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
Vector3f v {1.0, 0.0, 0.0};
|
||||
Vector3f yAxis {0.0, 1.0, 0.0};
|
||||
Vector3F v {1.0, 0.0, 0.0};
|
||||
Vector3F yAxis {0.0, 1.0, 0.0};
|
||||
float angle = M_PI / 2;
|
||||
|
||||
Quaternionf p = quaternionf(yAxis, angle);
|
||||
Quaternionf q;
|
||||
Vector3f vr {0.0, 0.0, 1.0};
|
||||
Vector3F vr {0.0, 0.0, 1.0};
|
||||
|
||||
assert(p.isUnitQuaternion());
|
||||
std::cerr << p.rotate(v) << std::endl;
|
||||
|
||||
@@ -58,7 +58,7 @@ Assert(bool condition)
|
||||
#else
|
||||
std::stringstream msg;
|
||||
|
||||
msg << "assertion failed at " << __FILE__ << ":" << __LINE__;
|
||||
msg << "assertion failed At " << __FILE__ << ":" << __LINE__;
|
||||
throw AssertionFailed(msg.str());
|
||||
#endif
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user