ROME 2 Lab5
Embed:
(wiki syntax)
Show/hide line numbers
Point.cpp
00001 /* 00002 * Point.cpp 00003 * Copyright (c) 2020, ZHAW 00004 * All rights reserved. 00005 */ 00006 00007 #include <cmath> 00008 #include "Point.h" 00009 00010 using namespace std; 00011 00012 /** 00013 * Creates a Point object. 00014 */ 00015 Point::Point() { 00016 00017 x = 0.0f; 00018 y = 0.0f; 00019 r = 0.0f; 00020 alpha = 0.0f; 00021 } 00022 00023 /** 00024 * Creates a Point object from given polar coordinates. 00025 * @param r the radius of a point. 00026 * @param alpha the angle of a point. 00027 */ 00028 Point::Point(float r, float alpha) { 00029 00030 x = r*cos(alpha); 00031 y = r*sin(alpha); 00032 00033 this->r = r; 00034 this->alpha = alpha; 00035 } 00036 00037 /** 00038 * Deletes this object. 00039 */ 00040 Point::~Point() {} 00041 00042 /** 00043 * Calculates the distance of this point from the origin. 00044 */ 00045 float Point::distance() { 00046 00047 return sqrt(x*x+y*y); 00048 } 00049 00050 /** 00051 * Calculates the distance between this point and a given point. 00052 * @param point another point to calculate the distance to. 00053 */ 00054 float Point::distance(Point& point) { 00055 00056 return sqrt((x-point.x)*(x-point.x)+(y-point.y)*(y-point.y)); 00057 } 00058 00059 /** 00060 * Calculates the manhattan distance of this point from the origin. 00061 * This calculation is only an approximation, but a lot faster to compute. 00062 */ 00063 float Point::manhattanDistance() { 00064 00065 return fabs(x)+fabs(y); 00066 } 00067 00068 /** 00069 * Calculates the manhattan distance between this point and a given point. 00070 * This calculation is only an approximation, but a lot faster to compute. 00071 * @param point another point to calculate the distance to. 00072 */ 00073 float Point::manhattanDistance(Point& point) { 00074 00075 return fabs(x-point.x)+fabs(y-point.y); 00076 } 00077
Generated on Thu Jul 14 2022 18:53:11 by
1.7.2