Skip to content

Commit

Permalink
Merge pull request #22 from ichiro-its/21-wrong-result-in-point2-dire…
Browse files Browse the repository at this point in the history
…ction

21 wrong result in point2 direction
  • Loading branch information
Nathan24zz authored Apr 25, 2021
2 parents 4949f0c + 99bf979 commit 0b72711
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 84 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ endif()

ament_export_include_directories("include")
ament_export_libraries(${PROJECT_NAME})

ament_package()
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Ichiro ITS
Copyright (c) 2021 ICHIRO ITS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Keisan is a [ROS 2](https://docs.ros.org/en/foxy/index.html) package that provid

## License

This project is maintained by [ICHIRO ITS](https://github.com/ichiro-its) and licensed under [the MIT License](./LICENSE).
This project is maintained by [ICHIRO ITS](https://github.com/ichiro-its) and licensed under the [MIT License](./LICENSE).
2 changes: 1 addition & 1 deletion include/keisan/angle.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion include/keisan/keisan.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion include/keisan/number.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
34 changes: 17 additions & 17 deletions include/keisan/point_2.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -30,32 +30,32 @@ struct Point2
Point2(double x, double y);
Point2(const Point2 & point);

Point2 & operator=(Point2 & point);
Point2 & operator+=(Point2 & point);
Point2 & operator-=(Point2 & point);
Point2 & operator=(const Point2 & point);
Point2 & operator+=(const Point2 & point);
Point2 & operator-=(const Point2 & point);

Point2 & operator+=(double value);
Point2 & operator-=(double value);
Point2 & operator*=(double value);
Point2 & operator/=(double value);

Point2 operator+(Point2 & point);
Point2 operator-(Point2 & point);
Point2 operator+(const Point2 & point) const;
Point2 operator-(const Point2 & point) const;

Point2 operator+(double value);
Point2 operator-(double value);
Point2 operator*(double value);
Point2 operator/(double value);
Point2 operator+(double value) const;
Point2 operator-(double value) const;
Point2 operator*(double value) const;
Point2 operator/(double value) const;

static double distance_between(Point2 & point_a, Point2 & point_b);
static double angle_between(Point2 & point_a, Point2 & point_b);
static double dot_product(Point2 & point_a, Point2 & point_b);
static double cross_product(Point2 & point_a, Point2 & point_b);
static double distance_between(const Point2 & point_a, const Point2 & point_b);
static double angle_between(const Point2 & point_a, const Point2 & point_b);
static double dot_product(const Point2 & point_a, const Point2 & point_b);
static double cross_product(const Point2 & point_a, const Point2 & point_b);

double magnitude();
double direction();
double magnitude() const;
double direction() const;

Point2 normalize();
Point2 normalize() const;

double x;
double y;
Expand Down
34 changes: 17 additions & 17 deletions include/keisan/point_3.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -30,32 +30,32 @@ struct Point3
Point3(double x, double y, double z);
Point3(const Point3 & point);

Point3 & operator=(Point3 & point);
Point3 & operator+=(Point3 & point);
Point3 & operator-=(Point3 & point);
Point3 & operator=(const Point3 & point);
Point3 & operator+=(const Point3 & point);
Point3 & operator-=(const Point3 & point);

Point3 & operator+=(double value);
Point3 & operator-=(double value);
Point3 & operator*=(double value);
Point3 & operator/=(double value);

Point3 operator+(Point3 & point);
Point3 operator-(Point3 & point);
Point3 operator+(const Point3 & point) const;
Point3 operator-(const Point3 & point) const;

Point3 operator+(double value);
Point3 operator-(double value);
Point3 operator*(double value);
Point3 operator/(double value);
Point3 operator+(double value) const;
Point3 operator-(double value) const;
Point3 operator*(double value) const;
Point3 operator/(double value) const;

static double distance_between(Point3 & point_a, Point3 & point_b);
static double angle_between(Point3 & point_a, Point3 & point_b);
static double dot_product(Point3 & point_a, Point3 & point_b);
static double cross_product(Point3 & point_a, Point3 & point_b);
static double distance_between(const Point3 & point_a, const Point3 & point_b);
static double angle_between(const Point3 & point_a, const Point3 & point_b);
static double dot_product(const Point3 & point_a, const Point3 & point_b);
static double cross_product(const Point3 & point_a, const Point3 & point_b);

double magnitude();
double direction();
double magnitude() const;
double direction() const;

Point3 normalize();
Point3 normalize() const;

double x;
double y;
Expand Down
4 changes: 2 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>keisan</name>
<version>0.1.0</version>
<description>A Math equations and algorithms package</description>
<version>0.2.0</version>
<description>Math equations and algorithms library</description>
<maintainer email="[email protected]">Alfi Maulana</maintainer>
<license>MIT License</license>
<buildtool_depend>ament_cmake</buildtool_depend>
Expand Down
2 changes: 1 addition & 1 deletion src/angle.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion src/number.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 18 additions & 18 deletions src/point_2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 Ichiro ITS
// Copyright (c) 2021 ICHIRO ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -44,23 +44,23 @@ Point2::Point2(const Point2 & point)
y = point.y;
}

Point2 & Point2::operator=(Point2 & point)
Point2 & Point2::operator=(const Point2 & point)
{
x = point.x;
y = point.y;

return *this;
}

Point2 & Point2::operator+=(Point2 & point)
Point2 & Point2::operator+=(const Point2 & point)
{
x += point.x;
y += point.y;

return *this;
}

Point2 & Point2::operator-=(Point2 & point)
Point2 & Point2::operator-=(const Point2 & point)
{
x -= point.x;
y -= point.y;
Expand Down Expand Up @@ -100,73 +100,73 @@ Point2 & Point2::operator/=(double value)
return *this;
}

Point2 Point2::operator+(Point2 & point)
Point2 Point2::operator+(const Point2 & point) const
{
return Point2(x + point.x, y + point.y);
}

Point2 Point2::operator-(Point2 & point)
Point2 Point2::operator-(const Point2 & point) const
{
return Point2(x - point.x, y - point.y);
}

Point2 Point2::operator+(double value)
Point2 Point2::operator+(double value) const
{
return Point2(x + value, y + value);
}

Point2 Point2::operator-(double value)
Point2 Point2::operator-(double value) const
{
return Point2(x - value, y - value);
}

Point2 Point2::operator*(double value)
Point2 Point2::operator*(double value) const
{
return Point2(x * value, y * value);
}

Point2 Point2::operator/(double value)
Point2 Point2::operator/(double value) const
{
return Point2(x / value, y / value);
}

double Point2::distance_between(Point2 & point_a, Point2 & point_b)
double Point2::distance_between(const Point2 & point_a, const Point2 & point_b)
{
double dx = point_a.x - point_b.x;
double dy = point_a.y - point_b.y;

return sqrt(dx * dx + dy * dy);
}

double Point2::angle_between(Point2 & point_a, Point2 & point_b)
double Point2::angle_between(const Point2 & point_a, const Point2 & point_b)
{
double dot = dot_product(point_a, point_b);
double mag = point_a.magnitude() * point_b.magnitude();

return wrap_rad(acos(dot / mag));
}

double Point2::dot_product(Point2 & point_a, Point2 & point_b)
double Point2::dot_product(const Point2 & point_a, const Point2 & point_b)
{
return point_a.x * point_b.x + point_a.y * point_b.y;
}

double Point2::cross_product(Point2 & point_a, Point2 & point_b)
double Point2::cross_product(const Point2 & point_a, const Point2 & point_b)
{
return point_a.magnitude() * point_b.magnitude() * sin(angle_between(point_a, point_b));
}

double Point2::magnitude()
double Point2::magnitude() const
{
return sqrt(x * x + y * y);
}

double Point2::direction()
double Point2::direction() const
{
return wrap_rad(atan(y / x));
return wrap_rad(atan2(y, x));
}

Point2 Point2::normalize()
Point2 Point2::normalize() const
{
double mag = magnitude();

Expand Down
Loading

0 comments on commit 0b72711

Please sign in to comment.