NXPCup_Cachan / Mbed 2 deprecated NXPCup

Dependencies:   mbed

Classes/Vector.cpp

Committer:
Wael_H
Date:
2020-02-11
Revision:
0:8743b606abc3
Child:
2:1103f5d61035

File content as of revision 0:8743b606abc3:

#include "Vector.h"
#include "math.h"

Vector::Vector(int x0, int y0, int x1, int y1)
{
    this->p0.x = x0;
    this->p0.y = y0;
    this->p1.x = x1;
    this->p1.y = y1;
}

Vector::Vector(Point p0, Point p1)
{
    this->p0 = p0;
    this->p1 = p1;
}

Vector::Vector()
{
}

void Vector::orienteVersLeHaut()
{
    if(this->p1.y > this->p0.y)
    {
        Point savep0 = this->p0;
        this->p0 = this->p1;
        this->p1 = savep0;
    }
}

float Vector::getCoeffDir() const
{
    return (float)(this->p0.y - this->p1.y) / (float)(this->p1.x - this->p0.x); // y inversés pcq console tsais
}

int Vector::getNorme() const
{
    return sqrt(pow((float)(this->p1.x - this->p0.x), 2) + pow((float)(this->p1.y - this->p0.y), 2));
}

bool Vector::estADroiteDe(Vector& v) const
{
    if(this->p1.x > v.p1.x)
        return true;
    return false;
}

Vector Vector::getVectorAuMilieuDe(Vector& v0, Vector& v1)
{
    static Vector vM;
    
    vM.p0.x = (v0.p0.x + v1.p0.x) / 2;
    vM.p0.y = (v0.p0.y + v1.p0.y) / 2;
    vM.p1.x = (v0.p1.x + v1.p1.x) / 2;
    vM.p1.y = (v0.p1.y + v1.p1.y) / 2;
    
    return vM;
}