2017-09-28 23:30:00 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-07-31 22:15:22 -07:00
|
|
|
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
2017-09-28 23:30:00 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/drive/Vector2d.h"
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
2019-07-31 22:15:22 -07:00
|
|
|
#include <wpi/math>
|
2017-09-28 23:30:00 -07:00
|
|
|
|
2019-07-31 22:15:22 -07:00
|
|
|
using namespace frc;
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
Vector2d::Vector2d(double x, double y) {
|
|
|
|
|
this->x = x;
|
|
|
|
|
this->y = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Vector2d::Rotate(double angle) {
|
2019-07-31 22:15:22 -07:00
|
|
|
double cosA = std::cos(angle * (wpi::math::pi / 180.0));
|
|
|
|
|
double sinA = std::sin(angle * (wpi::math::pi / 180.0));
|
2017-09-28 23:30:00 -07:00
|
|
|
double out[2];
|
|
|
|
|
out[0] = x * cosA - y * sinA;
|
|
|
|
|
out[1] = x * sinA + y * cosA;
|
|
|
|
|
x = out[0];
|
|
|
|
|
y = out[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double Vector2d::Dot(const Vector2d& vec) const {
|
|
|
|
|
return x * vec.x + y * vec.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double Vector2d::Magnitude() const { return std::sqrt(x * x + y * y); }
|
|
|
|
|
|
|
|
|
|
double Vector2d::ScalarProject(const Vector2d& vec) const {
|
|
|
|
|
return Dot(vec) / vec.Magnitude();
|
|
|
|
|
}
|