Objet Point et Triangle pb a la compilation

cs_fatcat Messages postés 8 Date d'inscription mardi 12 novembre 2002 Statut Membre Dernière intervention 3 juin 2004 - 26 avril 2004 à 16:27
cs_fatcat Messages postés 8 Date d'inscription mardi 12 novembre 2002 Statut Membre Dernière intervention 3 juin 2004 - 30 avril 2004 à 14:29
Salut a tous
Voila mon petit pb
Je dois créer un programme qui effectue une triangulation de delauanay a partir d un fichier de Point avec 2 "double" comme attributs
J ai cée 2 objet, Point et Triangle
Et j ai des erreurs a la compilation

Point.h
#ifndef _POINT__H
#define _POINT__H
#include 
//#include 
using namespace std;

class Point
{
  protected:
  double x,y;

  public:
      Point(double 0.0, double0.0);

    double dist(const Point&);

    double abs() const;
    double ord() const;
    bool isEqual(const Point&) const;

    void deplacer(double, double);
    void rotation(const Point&, double);
    void zoom(const Point&, double);

    void afficher() const;
};
#endif


Point.cpp
#include 
#include "Point.h"
#include <math.h>
using namespace std;

Point::Point(double xx,double yy)
{
x  = xx;
y =  yy;
}

double Point::dist(const Point &p1)
{
return sqrt((x-p1.x)*(x-p1.x)+(y-p1.y)*(y-p1.y));
}

double Point::abs() const
{
return x;
}

double Point::ord() const
{
return y;
}

bool Point::isEqual(const Point &p1) const
{
  return (x==p1.x && y==p1.y);
}

void Point::deplacer(double dx,double dy)
{
x += dx;
y += dy;
}

void Point::rotation(const Point &w,double theta)
{
double d = dist(w);
double alpha = acos((x-w.x)/sqrt((x-w.x)*(x-w.x)+(y-w.y)*(y-w.y)));
double beta = asin((y-w.y)/sqrt((x-w.x)*(x-w.x)+(y-w.y)*(y-w.y)));
theta = theta*M_PI/180.;
if (d!=0)
        {
  x = w.x + d*cos(theta + alpha);
  y = w.y + d*sin(theta + beta);
}
}

void Point::zoom(const Point& a,double k)
{
x = (x-a.x)*k + a.x;
y = (y-a.y)*k + a.y;
}

void Point::afficher() const
{
cout << "{"<< x << " ; "<< y<< "}";
}


Triangle.h
#ifndef _TRIANGLE__H
#define _TRIANGLE__H

#include 
#include "Point.h"
using namespace std;

class Triangle
{
 protected:
  Point* a;
  Point* b;
  Point* c;
  Triangle* t1;
  Triangle* t2;
  Triangle* t3;

 public:
  Triangle(Point*, Point*, Point*, Triangle*, Triangle*, Triangle*);
  Triangle(Point*, Point*, Point*);
  Triangle();

  Point centreCC() const;
  Point sommet(int i) const;

  double rayon() const;
  void deplacer(double, double);	  
  void rotation(const Point&, double);
  void zoom(const Point&, double);

  void afficherT() const;
};
#endif


Triangle.cpp
#include 
#include "Triangle.h"
using namespace std;

Triangle::Triangle(Point *aa, Point *bb, Point *cc, Triangle *tt1, Triangle *tt2, Triangle *tt3)
{
a  =aa;
b = bb;
c =cc;
t1 =tt1;
t2 =tt2;
t3 =tt3;
}
Triangle::Triangle(Point *a, Point *b, Point *c)
{
  t1 = NULL;
  t2 = NULL;
  t3 = NULL;
}

Triangle::Triangle()
{
  a = NULL;
  b = NULL;
  c = NULL;
  t1 = NULL;
  t2 = NULL;
  t3 = NULL;

}

Point Triangle::centreCC() const
{
double x1,x2,x3,y1,y2,y3;
double p,q,r,s,t,u;

x1=a.x;
x2=b.x;
x3=c.x;
y1=a.y;
y2=b.y;
y3=c.y;
if (!a.isEqual(b) && !a.isEqual(c) && !b.isEqual(c))
{
  p=x2-x3;
  q=y2-y3;
  r=((y2+y3)*(y2-y3)+(x2+x3)*(x2-x3))/2.;
  s=x2-x1;
  t=y2-y1;
  u=((y2+y1)*(y2-y1)+(x2+x1)*(x2-x1))/2.;
         
  Point cc(((r*t-u*q)/(p*t-q*s)),((s*r-p*u)/(q*s-p*t)));
  return cc;
}
if (a.isEqual(b) && !a.isEqual(c))
{
  Point cc((a.x+c.x)/2.,(a.y+c.y)/2);
  return cc;
}
if (a.isEqual(c) && !a.isEqual(b))
{
  Point cc((a.x+b.x)/2,(a.y+b.y)/2);
  return cc;
}
if (c.isEqual(b) && !c.isEqual(a))
{
  Point cc((b.x+c.x)/2,(b.y+c.y)/2);
  return cc;
}
if (a.isEqual(c) && a.isEqual(b))
{
  Point cc(0,0);
  return cc;
}
}

Point Triangle::sommet(int i) const
{
if (i==1) return a;
if (i==2) return b;
if (i==3) return c;
}

double Triangle::rayon() const
// rayon du cercle circonscrit au triangle
{
return a.dist(centreCC());
}

void Triangle::deplacer(double dx,double dy)
{
a.deplacer(dx,dy);
b.deplacer(dx,dy);
c.deplacer(dx,dy);
}

void Triangle::rotation(const Point &w,double theta)
{
a.rotation(w,theta);
b.rotation(w,theta);
c.rotation(w,theta);
}

void Triangle::zoom(const Point &w, double k)
{
a.zoom(w, k);
b.zoom(w, k);
c.zoom(w, k);
}

void Triangle::afficherT() const
{
  a.afficher();
  cout << " | ";
  b.afficher();
  cout << " | ";
  c.afficher();
}


makefile
# Path for the Tcontainer project
#
INC_DIR  = ../header

#
# Path for the Algebra project
#SRC_DIR BIN_DIR ../bin/
INC_DIR = ../header

CCC = g++
#
# Global Flags
#
ALG_FLAGS = -O2 -g -Wno-deprecated

#
# header files needed
#
INCLUDES = -I$(INC_DIR)

#
# Targets
#
all: test

SRCS    = 	Point.cpp 	Triangle.cpp

TEST_SRCS = Test.cpp

#
# Règles de compilation des modules
#

OBJS= $(SRCS:%.cc=$(BIN_DIR)%.o)
TEST_OBJS= $(TEST_SRCS:%.cc=$(BIN_DIR)%.o)

$(BIN_DIR)%.o: %.cc
$(CCC) $(INCLUDES) $(ALG_FLAGS) $< -c -o $@

#
#       executable de test
#
test : $(OBJS) $(TEST_OBJS)
$(CCC) $(INCLUDES) $(CCCFLAGS) $(ALG_FLAGS)  -o  $(BIN_DIR)$@ $(OBJS) $(TEST_OBJS) -lm


quand je lance la compilation voila ce qu il me sort

Triangle.cpp:51: error: request for member `x' in `this->Triangle::a', which is
of non-class type `Point* const'

Triangle.cpp:57: error: request for member `isEqual' in `this->Triangle::a',
which is of non-aggregate type `Point* const

Triangle.cpp:93: error: conversion from `Point* const' to non-scalar type `
Point' requested

Triangle.cpp:117: error: request for member `deplacer' in `this->Triangle::a',
which is of non-aggregate type `Point*

je n ai que ce type d erreur mais plusieurs

Si qqun a une solution ca m aiderait bcp
Merci

4 réponses

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
28 avril 2004 à 01:15
a, b, c, t1, t2, et t3 sont des pointeurs dans la classe Triangle, l'accès au membre se fait avec "->" et pas "."
0
cs_fatcat Messages postés 8 Date d'inscription mardi 12 novembre 2002 Statut Membre Dernière intervention 3 juin 2004
28 avril 2004 à 14:00
Merci
Quelle erreur de newb :)
autre pb maintenant
voila mon test.cpp
#include 
#include <math.h>
#include "Point.h"
#include "Triangle.h"
using namespace std;

int main (int argc, char** argv)
{
double x,y;
double theta;
cout << "entrez les coord de a:" << endl;
cout << "x : ";
cin >> x;
cout << "y : ";
cin >> y;
Point a(x,y);
cout << "entrez les coord de b:" << endl;
cout << "x : ";
cin >> x;
cout << "y : ";
cin >> y;
Point b(x,y);
cout << "entrez les coord de c:" << endl;
cout << "x : ";
cin >> x;
cout << "y : ";
cin >> y;
Point c(x,y);
cout << "entrez les coord du centre de rotation:" << endl;
cout << "x : ";
cin >> x;
cout << "y : ";
cin >> y;
cout << "entrez l angle de rotation (en degres):";
cin >> theta;

Triangle T(a,b,c);

T.centreCC().afficher();
cout << endl;

//	T.sommet(1).afficher();
//	cout << endl;

T.afficherT();
cout << endl;

T.rotation(Point(x,y),theta);

T.afficherT();
cout << endl;

T.centreCC().afficher();
cout << endl;

return 0;
}


et il me renvoie cette erreur

*Test.cpp [Warning] In function `int main(int, char**)':

*37 Test.cpp no matching function for call to Triangle::Triangle(Point&,

*22 Triangle.h candidates are: Triangle::Triangle(const Triangle&)

*34 Triangle.h Triangle::Triangle()

*33 Triangle.h Triangle::Triangle(Point*, Point*, Point*)

*32 Triangle.h Triangle::Triangle(Point*, Point*, Point*,

je sais que l erreur vien de la ligne
Triangle T(a,b,c); dans test.cpp
mais je vois pas comment faire
0
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
28 avril 2004 à 22:03
même erreur, ton constructeur attent des pointeurs, il faut lui les donner:
Triangle T(&a,&b,&c);
0
cs_fatcat Messages postés 8 Date d'inscription mardi 12 novembre 2002 Statut Membre Dernière intervention 3 juin 2004
30 avril 2004 à 14:29
Un grand merci la compilation marche.
Mon pb maintenant c est que chaque fois que le prog fait une operation sur un triangle (rotation, deplacement, affichage...) j ai une erreur de segmentation
voila un lien vers les sources
http://frandop.chez.tiscali.fr/iut/projet.tar.gz
0
Rejoignez-nous