Test du path finding

Dependencies:   RoboClaw mbed

Fork of TestMyPathFind by Romain Ame

map/figure.h

Committer:
IceTeam
Date:
2016-04-13
Revision:
41:53d5990ff99d
Parent:
39:ca4dd3faffa8

File content as of revision 41:53d5990ff99d:

#ifndef FIGURE_H
#define FIGURE_H

#include "point.h"

class figure {
public:
    figure(float xc, float yc) {
        xcentre = xc;
        ycentre = yc;
    }

    float getX () { return xcentre; }
    float getY () { return ycentre; }

    bool CroisementSegment (point A1, point A2, point B1, point B2) {
        if (ProdVect (A1, A2, B1, B2) != 0) { // On verifie que les droites ne sont pas parallèles
            if (ProdVect (A1, A2, A1, B2)*ProdVect (A1, A2, A1, B1) <= 0
                && ProdVect (B1, B2, B1, A1)*ProdVect (B1, B2, B1, A2) <= 0) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }

protected:
    float xcentre, ycentre;

    float ProdVect (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
        return ((x2 - x1)*(y4 - y3) - (y2 - y1)*(x4 - x3));
    }
    float ProdVect (point A1, point A2, point B1, point B2) {
        return ProdVect (A1.getX(), A1.getY (), A2.getX (), A2.getY (), B1.getX (), B1.getY (), B2.getX (), B2.getY ());
    }
};
#endif