/* * Geometric_Object.cc 2013-08-26 */ #include "Geometric_Object.h" #include using namespace std; /* * Point */ string Point::to_str() const { return "Point@[x=" + std::to_string(x) + ",y=" + std::to_string(y) + ']'; } Point* Point::clone() const { return new Point{ *this }; } /* * Line */ double Line::get_length() const { return sqrt((x2_ - x1_)*(x2_ - x1_) +(y2_ - y1_)*(y2_ - y1_)); } string Line::to_str() const { return "Line@[x1=" + std::to_string(x1_) + ",y1=" + std::to_string(y1_) + ",x2=" + std::to_string(x2_) + ",y2=" + std::to_string(y2_) + ']'; } Line* Line::clone() const { return new Line{ *this }; } /* * Circle */ double Circle::get_area() const { return M_PI * r_ * r_; } double Circle::get_profile() const { return 2.0 * M_PI * r_; } double Circle::get_radius() const { return r_; } string Circle::to_str() const { return "Circle@[r=" + std::to_string(r_) + ']'; } Circle* Circle::clone() const { return new Circle{ *this }; } /* * Circular_Cylinder */ double Circular_Cylinder::get_area() const { return 2 * Circle::get_area() + get_profile() * h_; } double Circular_Cylinder::get_volume() const { return Circle::get_area() * h_; } double Circular_Cylinder::get_height() const { return h_; } string Circular_Cylinder::to_str() const { return "Circular_Cylinder@[r=" + std::to_string(r_) + ",h=" + std::to_string(h_) + ']'; } Circular_Cylinder* Circular_Cylinder::clone() const { return new Circular_Cylinder{ *this }; } /* * Rectangle */ double Rectangle::get_area() const { return a_ * b_; } double Rectangle::get_profile() const { return 2 * (a_ + b_); } double Rectangle::get_a() const { return a_; } double Rectangle::get_b() const { return b_; } string Rectangle::to_str() const { return "Rectangle@[a=" + std::to_string(a_) + ",b=" + std::to_string(b_) + ']'; } Rectangle* Rectangle::clone() const { return new Rectangle{ *this }; } /* * Rectangular_Parallelepiped */ double Rectangular_Parallelepiped::get_area() const { return 2 * (get_a() * get_b() + get_a() * c_ + get_b() * c_); } double Rectangular_Parallelepiped::get_volume() const { return get_a() * get_b() * c_; } double Rectangular_Parallelepiped::get_c() const { return c_; } string Rectangular_Parallelepiped::to_str() const { return "Rectangular_Parallelepiped@[a=" + std::to_string(get_a()) + ",b=" + std::to_string(get_b()) + ",c=" + std::to_string(c_) + ']'; } Rectangular_Parallelepiped* Rectangular_Parallelepiped::clone() const { return new Rectangular_Parallelepiped{ *this }; } /* * Triangle */ double Triangle::get_profile() const { return a_ + b_ + c_; } double Triangle::get_a() const { return a_; } double Triangle::get_b() const { return b_; } double Triangle::get_c() const { return c_; } double Triangle::get_area() const { double cos_theta{ (b_ * b_ + c_ * c_ - a_ * a_) / (2 * b_ * c_) }; double h{ c_ * sqrt(1 - cos_theta * cos_theta) }; return b_ * h / 2; } string Triangle::to_str() const { return "Triangle@[a=" + std::to_string(a_) + ",b=" + std::to_string(b_) + ",c=" + std::to_string(c_) + ']'; } Triangle* Triangle::clone() const { return new Triangle{ *this }; } /* * Triangular_Prism */ double Triangular_Prism::get_area() const { return 2 * Triangle::get_area() + (a_ + b_ + c_) * h_; } double Triangular_Prism::get_volume() const { return Triangle::get_area() * h_; } double Triangular_Prism::get_height() const { return h_; } string Triangular_Prism::to_str() const { return "Triangular_Prism@[a=" + std::to_string(a_) + ",b=" + std::to_string(b_) + ",c=" + std::to_string(c_) + ",h=" + std::to_string(h_) + ']'; } Triangular_Prism* Triangular_Prism::clone() const { return new Triangular_Prism{ *this }; }