📄 point.cpp
字号:
//////////////////////////////////////////////////////////////////////
// Title: Geographic Load Balancing for Cellular Networks
// by emulating the behavior of air bubbles
//
// Description: This project is for dynamically balancing the traffic load
// over a cellular network with fully adaptive antennas by
// emulating the behaviours of a bubble array. Since
// we assume fully adaptive base station antenna in this
// version, antenna agent and simulator are not needed.
//
// Copyright: Copyright (c) 2003
// Company: Elec. Eng. Dept., Queen Mary, University of London
// @author Lin Du (lin.du@elec.qmul.ac.uk)
// @version 1.0
//
//////////////////////////////////////////////////////////////////////
#include "Point.h"
Point::Point() {
dX = 0;
dY = 0;
}
Point::Point(double X, double Y) {
dX = X;
dY = Y;
}
double Point::getX() const {
return dX;
}
double Point::getY() const {
return dY;
}
void Point::set(double X, double Y) {
dX = X;
dY = Y;
}
void Point::set(const Point &p) {
dX = p.dX;
dY = p.dY;
}
double Point::distance2(const double X1, const double Y1, const double X2, const double Y2) const {
return ((Y1-Y2) * (Y1-Y2) + (X1-X2) * (X1-X2));
}
double Point::distance(double X, double Y) const{
return sqrt((Y-dY) * (Y-dY) + (X-dX) * (X-dX));
}
double Point::distance2(double X, double Y) const{
return ((Y-dY) * (Y-dY) + (X-dX) * (X-dX));
}
double Point::distance(const Point &p) const {
return sqrt((p.dY-dY) * (p.dY-dY) + (p.dX-dX) * (p.dX-dX));
}
double Point::distance2(const Point &p) const {
return (p.dY-dY) * (p.dY-dY) + (p.dX-dX) * (p.dX-dX);
}
/**
* Return the angle(from first/this point to second point) in degree
*/
double Point::angle(double X, double Y) const {
double ang = rad2Deg(atan2(Y-dY, X-dX));
if (ang < 0) ang += 360.0;
return ang;
}
double Point::angle(const Point &p) const {
double ang = rad2Deg(atan2(p.dY-dY, p.dX-dX));
if (ang < 0) ang += 360.0;
return ang;
}
// return the angle from zero point to this point) in degree
double Point::angle() const {
double ang = rad2Deg(atan2(dY, dX));
if (ang < 0) ang += 360.0;
return ang;
}
// Return the magnitude of the point ( equal to the distance to the point(0,0) )
double Point::magnitude() const{
return distance(0,0);
}
// Overload operators
bool operator>(const Point &p1, const Point &p2) {
return p1.magnitude() > p2.magnitude();
}
bool operator<(const Point &p1, const Point &p2) {
return p1.magnitude() < p2.magnitude();
}
Point operator+(const Point &p1, const Point &p2) {
Point t;
t.dX = p1.dX + p2.dX;
t.dY = p1.dY + p2.dY;
return t;
}
Point operator-(const Point &p1, const Point &p2) {
Point t;
t.dX = p1.dX - p2.dX;
t.dY = p1.dY - p2.dY;
return t;
}
Point operator*(const Point &p1, const double val) {
Point t;
t.dX = p1.dX * val;
t.dY = p1.dY * val;
return t;
}
Point operator/(const Point &p1, const double val) {
Point t;
t.dX = p1.dX / val;
t.dY = p1.dY / val;
return t;
}
Point& Point::operator+=(const Point &p1){
dX += p1.dX;
dY += p1.dY;
return *this;
}
Point& Point::operator-=(const Point &p1){
dX -= p1.dX;
dY -= p1.dY;
return *this;
}
Point& Point::operator*=(const double val) {
dX *= val;
dY *= val;
return *this;
}
Point& Point::operator/=(const double val) {
dX /= val;
dY /= val;
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -