pmc/pmc.cc
changeset 42 83b8151b966d
parent 41 574503cf7bb0
child 43 cf8c1b5127b2
equal deleted inserted replaced
41:574503cf7bb0 42:83b8151b966d
     1 /**
       
     2  * test/demos/pmc/pmc.cc
       
     3  * Copyright (C) 2008 Markus Broeker
       
     4  */
       
     5 
       
     6 #include <iostream>
       
     7 #include <cmath>
       
     8 #include <pmc.h>
       
     9 
       
    10 using namespace pmc;
       
    11 
       
    12 Vector::Vector (int xx, int yy, int zz)
       
    13 {
       
    14     name = "Vector";
       
    15     x = xx;
       
    16     y = yy;
       
    17     z = zz;
       
    18     mode = RAD;
       
    19 }
       
    20 
       
    21 Vector::~Vector ()
       
    22 {
       
    23 }
       
    24 
       
    25 int Vector::X ()
       
    26 {
       
    27     return x;
       
    28 }
       
    29 
       
    30 int Vector::Y ()
       
    31 {
       
    32     return y;
       
    33 }
       
    34 
       
    35 int Vector::Z ()
       
    36 {
       
    37     return z;
       
    38 }
       
    39 
       
    40 Vector Vector::operator+ (Vector a)
       
    41 {
       
    42     return Vector (x + a.X (), y + a.Y (), z + a.Z ());
       
    43 }
       
    44 
       
    45 Vector Vector::operator- (Vector a)
       
    46 {
       
    47     return Vector (x - a.X (), y - a.Y (), z - a.Z ());
       
    48 }
       
    49 
       
    50 int Vector::operator* (Vector a)
       
    51 {
       
    52     return (x * a.X () + y * a.Y () + z * a.Z ());
       
    53 }
       
    54 
       
    55 double Vector::abs ()
       
    56 {
       
    57     return (std::sqrt (x * x + y * y + z * z));
       
    58 }
       
    59 
       
    60 void Vector::vector ()
       
    61 {
       
    62     std::cout << "(" << x << ", " << y << ", " << z << ")";
       
    63 }
       
    64 
       
    65 double Vector::angle (Vector p)
       
    66 {
       
    67     if (mode == DEG)
       
    68         return ((180.0 / M_PI) * std::acos ((p ** this) / (abs () * p.abs ())));
       
    69 
       
    70     return (std::acos ((p ** this) / (abs () * p.abs ())));
       
    71 }
       
    72 
       
    73 void Vector::setMode (Mode m)
       
    74 {
       
    75     mode = m;
       
    76 }