/// @file   main.cpp
/// @author Jens Gruschel
/// @date   2016-07-14
/// Point-Typ mit Multiplikationsoperatoren

#include <iostream>

using std::cout;
using std::endl;

/// dreidimensionaler Punkt
struct Point
{
    double x;
    double y;
    double z;
};

/// Multiplikation einer Zahl mit einem Vektor
Point operator*(const double factor, const Point& p)
{
    Point result;
    result.x = factor * p.x;
    result.y = factor * p.y;
    result.z = factor * p.z;
    return result;
}

/// Multiplikation eines Vektors mit einer Zahl
Point operator*(const Point& p, const double factor)
{
    Point result;
    result.x = factor * p.x;
    result.y = factor * p.y;
    result.z = factor * p.z;
    return result;
}

/// Skalarprodukt zweier Vektoren
double operator*(const Point& a, const Point& b)
{
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

/// Kreuzprodukt zweier Vektoren
Point cross(const Point& a, const Point& b)
{
    Point result;
    result.x = a.y * b.z - a.z * b.y;
    result.y = a.z * b.x - a.x * b.z;
    result.z = a.x * b.y - a.y * b.x;
    return result;
}

/// Punktkoordinaten auf Konsole ausgeben
void print(const Point& p)
{
    cout << "x: " << p.x << endl;
    cout << "y: " << p.y << endl;
    cout << "z: " << p.z << endl;
}

int main()
{
    // Punkt definieren
    Point p;
    p.x = 1.0;
    p.y = 2.0;
    p.z = 3.0;

    // Multiplikation durchfuehren
    Point q = 0.2 * p;

    // Ergebnis ausgeben
    print(p);
    print(q);

    // Skalarprodukt und Kreuzprodukt berechnen
    cout << "Skalarprodukt: " << p * q << endl;
    print(cross(p, q));

    return 0;
}