IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C++ Discussion :

*this usage est incorrect ?


Sujet :

C++

  1. #1
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut *this usage est incorrect ?
    Bonjour, demandez de l’aide: le programme doit calculer l’intersection de deux lignes droites dans un plan. Malheureusement, le résultat pour la valeur y est faux, la méthode graphique donne: Y = 2,8 , le programme y= 3,7; Mon application est-elle erronée avec *this? Merci.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    class Point { // Un mesenger
    public:
    	float x, y, z; // Puisque c’est juste un transporteur
    	Point() { x = 0.0; y = 0.0; z = 0.0; }
    	Point(float xi, float yi, float zi) : x(xi), y(yi), z(zi) {}
    	Point(const Point& p) : x(p.x), y(p.y), z(p.z) {}
    	Point& operator=(const Point rhs) {
    		x = rhs.x;
    		y = rhs.y;
    		z = rhs.z;
    		return *this;
    	}
    	friend ostream&
    		operator<<(ostream& os, const Point& p) {
    		return os << " x=" << p.x << " y=" << p.y << " z=" << p.z;
    	}
    };
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    class Line : public Point {	//?!?
    	Point po1, po2;
    public:
    	Line(Point poi1, Point poi2) : po1{ poi1 }, po2{ poi2 }{}
    	float coin() { return atan((po2.y - po1.y) / (po2.x - po1.x)); }
     
    	float x2_x1(Line li) const {
    		return (li.po2.x - li.po1.x);
    	}
    	float y2_y1(Line li) const {
    		return (li.po2.y - li.po1.y);
    	}
    	float x3y4_y3x4(Line Li1, Line li2) const {
    		return (li2.po1.x * li2.po2.y - li2.po1.y * li2.po2.x);
    	}
    	float x1y2_y1x2(Line li1, Line li2) const{
    		return (li1.po1.x * li1.po2.y - li1.po1.y * li1.po2.x);
    	}
    	float dénominateur(Line li1, Line li2) const{ return (x2_x1(li1) * y4_y3(li2) - y2_y1(li1) * x4_x3(li2)); }
     
    	Point& intersection( Line li2) {
     
    		this->po1.x = (x2_x1(*this) * x3y4_y3x4(*this, li2) - x4_x3(li2) * x1y2_y1x2(*this, li2))
    			/ dénominateur(*this, li2);
    		this->po1.y = (y2_y1(*this) * x3y4_y3x4(*this, li2) - y4_y3(li2) * x1y2_y1x2(*this, li2)) 
    			/ dénominateur(*this, li2);
    		return this->po1;
    	}
     
    	float x4_x3(Line lin2) const { return (lin2.po2.x - lin2.po1.x); }
    	float y4_y3(Line lin2) const{ return (lin2.po2.y - lin2.po1.y); }
    };
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    int main(){
    	Point pA(3.5, 4, 0);
    	Point pB(-4, 2, 0);
    	Point pC(2, -2, 0);
    	Point pD(-2.0, 5, 0);
     
    	Line gérades1(pA, pB);
    	Line gérades2(pC, pD);
     
    	cout <<  gérades1.intersection( gérades2);	//	intersection_d_deux_lignes_droites
     
    }

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 144
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 144
    Points : 1 676
    Points
    1 676
    Par défaut
    Salut,

    Tu as déja un problème de conception.
    Pourquoi Line hérite de Point ?
    Une ligne n'est pas un point, c'est un agrégat d'au moins 2 points.

    Ensuite, les fonctions membre de la classe Line n'opèrent pas sur l'instance courante.
    Soit il faut les revoir, soit elle n'ont rien à faire là.

  3. #3
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut this
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    float x1y2_y1x2(Line li1, Line li2) const{
    		return (li1.po1.x * li1.po2.y - li1.po1.y * li1.po2.x);
    x1y2_y1x2(this) = -5.63 ?
    x1y2_y1x2 = 7.5 * 4 - (-3) * (-5.5) = 13.5

    this (pP(7.5,-3)
    pQ(-5.5, 4)
    pR(5,3)
    pS(-1,-6)
    https://scontent-vie1-1.xx.fbcdn.net...qw&oe=63BABB04

    Merci

  4. #4
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 144
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 144
    Points : 1 676
    Points
    1 676
    Par défaut
    D'où proviennent tes formules ?

    Perso, j'ai ca: https://calculis.net/intersection

  5. #5
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9

  6. #6
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut Merci de votre aide
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    class Line  {	
    	Point po1, po2;
    public:
    	Line(Point poi1, Point poi2) : po1{ poi1 }, po2{ poi2 }{}
    	float coin() { return atan((po2.y - po1.y) / (po2.x - po1.x)); }
     
    	float x2_x1() const {
    		return (po2.x - po1.x);
    	}
    	float y2_y1() const {
    		return (po2.y - po1.y);
    	}
    	float x3y4_y3x4( Line li2) const {
    		return (li2.po1.x * li2.po2.y - li2.po1.y * li2.po2.x);
    	}
    	float x1y2_y1x2() const{
    		return (po1.x * po2.y - po1.y * po2.x);
    	}
    	float dénominateur(Line li2) const{ return (x2_x1() * y4_y3(li2) - y2_y1() * x4_x3(li2)); }
     
    	float x4_x3(Line lin2) const { return (lin2.po2.x - lin2.po1.x); }
    	float y4_y3(Line lin2) const{ return (lin2.po2.y - lin2.po1.y); }
    	Point& intersection(Line li2);
    };
    Point po;
    Point& Line::intersection(Line li2) {
     
    	po.x = (x2_x1() * x3y4_y3x4(li2) - x4_x3(li2) * x1y2_y1x2())
    		/ dénominateur(li2);
    	po.y = (y2_y1() * x3y4_y3x4(li2) - y4_y3(li2) * x1y2_y1x2())
    		/ dénominateur(li2);
    	return po;
    }

  7. #7
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 144
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 144
    Points : 1 676
    Points
    1 676
    Par défaut
    Je craint de ne pas comprendre la langue de Goethe.

    Ton code est plutôt compliqué, j'ai refait à ma sauce (en 2D), en citant mes sources, à toi de compléter:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    #include <iostream>
    #include <string>
     
    class Point
    {
    private:
    	float mX, mY;
    public:
    	Point() :
    		mX{ 0 },
    		mY{ 0 }
    	{}
    	Point(float x, float y) :
    		mX{ x }, 
    		mY{ y }
    	{}
    	Point(Point const& p) : 
    		mX{ p.mX },
                    mY{ p.mY }
    	{}
    	Point& operator=(Point const& rhs) {
    		mX = rhs.mX;
    		mY = rhs.mY;
    		return *this;
    	}
    	float x() const
    	{
    		return mX;
    	}
    	float y() const
    	{
    		return mY;
    	}
    	friend std::ostream&
    		operator<<(std::ostream& os, Point const& p) {
    		return os << "x = " << p.mX << " y = " << p.mY;
    	}
    };
     
    class Segment
    {
    private:
    	Point mA, mB;
    public:
    	Segment(Point A, Point B) :
    		mA{ A }, mB{ B }
    	{}
    	float A() const		// Coefficient A: y = Ax + B
    	{
    		// a = (y1 - y2 ) / (x1 - x2)
    		// source: https://calculis.net/droite
                        // A completer
    	}
    	float B() const		// Coefficient B: y = Ax + B
    	{
    		// b = y1 - a * x1
    		// source: https://calculis.net/droite
                        // A completer
    	}
    	Point intersection(Segment const& other)
    	{
    		// x = (B' - B) / (A - A')
    		// source: https://calculis.net/intersection
                        // A completer
                    // y = A * x + B
                        // A completer
                   return Point{ x, y };
    	}
    	std::string equation() const
    	{
    		return "y = " + std::to_string(A()) + "x + " + std::to_string(B());
    	}
    };
     
    int main() {
    	Point A(3.5f, 4.0f);
    	Point B(-4.0f, 2.0f);
    	Point C(2.0f, -2.0f);
    	Point D(-2.0f, 5.0f);
     
    	Segment Line1(A, B);
    	std::cout << Line1.equation() << std::endl;
    	Segment Line2(C, D);
    	std::cout << Line2.equation() << std::endl;
     
    	std::cout << Line1.intersection(Line2);	// Point d'intersection des deux lignes droites
    }
    PS: Evite less accents dans les noms de variable, ce n'est pas portable.

  8. #8
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut Merci de votre aide
    Je serai heureux de le faire.
    (Les traducteurs numériques deviennent de plus en plus puissants.)

  9. #9
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut Ostream ne fonctionne pas?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    class Point
    {
    private:
    	float mX, mY;
    public:
    	Point() :
    		mX{ 0 },
    		mY{ 0 }
    	{}
    	Point(float x, float y) :
    		mX{ x },
    		mY{ y }
    	{}
    	Point(Point const& p) :
    		mX{ p.mX },
    		mY{ p.mY }
    	{}
    	Point& operator=(Point const& rhs) {
    		mX = rhs.mX;
    		mY = rhs.mY;
    		return *this;
    	}
    	float x() const
    	{
    		return mX;
    	}
    	float y() const
    	{
    		return mY;
    	}
    	void set_x( float xx) 
    	{
    		 mX = xx;
    	}
    	void set_y(float yy) 
    	{
    		mY = yy;
    	}
    	friend std::ostream&
    		operator<<(std::ostream& os, Point const& p) {
    		return os << "x = " << p.mX << " y = " << p.mY;
    	}
    };
    class Kurve : public Point {
    	std::vector<Point> kur;
    	Point pointBegin, pointEnd;
     
    public:
    	Kurve(Point pB, Point pE, std::initializer_list<Point> liste) : pointBegin{ pB }, pointEnd{ pE }, kur{ liste } {}
    	Kurve(Point pB, Point pE, Point p) : pointBegin{ pB }, pointEnd{ pE } {
    		kur.push_back(p);
    	}
     
    	friend std::ostream&
    		operator<<(std::ostream& os, Kurve& const k) {
    		auto it = k.kur.begin();
    		while (it != k.kur.end())
    			return os << *it++ << std::endl;
     
    	}
    };
     
     
    class Segment
    {
    private:
    	Point mA, mB;
    public:
    	Segment(Point A, Point B) :
    		mA{ A }, mB{ B }
    	{}
    	float A() const		// Coefficient A: y = Ax + B
    	{
    		return (mA.y() - mB.y()) / (mA.x() - mB.x());
    		// source: https://calculis.net/droite
    					// A completer
    	}
    	float B() const		// Coefficient B: y = Ax + B
    	{
    		return mA.y() - A() * mA.x();
    		// source: https://calculis.net/droite
    					// A completer
    	}
    	Point intersection(Segment const& other)
    	{
    		float x = (other.B() - B()) / (A() - other.A());
    					// source: https://calculis.net/intersection
    					// A completer
     
    					// A completer
    		return Point{x , A() * x + B()};
    	}
    	std::string equation() const
    	{
    		return "y = " + std::to_string(A()) + "x + " + std::to_string(B());
    	}
    };
    int main() {
    	Point pA(0, 0);
    	Point pB(2, pow(2, 2));
     
    	Point arr[10] = {};
    	//std::initializer_list<Point>  ini = arr;
     
    	for (int i = 0; i < 10; i++) {
    		arr[i].set_x(i);
    		arr[i].set_y( pow(i, 2));
    	}
    	Kurve parabol(pA, pB, *arr );
    	std::cout << parabol;
     
     
    	Point A(3.5f, 4.0f);
    	Point B(-4.0f, 2.0f);
    	Point C(2.0f, -2.0f);
    	Point D(-2.0f, 5.0f);
     
    	Segment Line1(A, B);
    	std::cout << Line1.equation() << std::endl;
    	Segment Line2(C, D);
    	std::cout << Line2.equation() << std::endl;
     
    	std::cout << Line1.intersection(Line2);	// Point d'intersection des deux lignes droites	
    }
    https://www.facebook.com/photo/?fbid...00424871458237

    Merci deedolith

  10. #10
    Expert éminent
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 566
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 566
    Points : 7 652
    Points
    7 652
    Par défaut
    tel que tu as écris ton operator<<, le paramètre k est incorrect et l'opérateur va retourner dès le premier élément. Et s'il n'y en a aucun va faire nimporte quoi. D'ailleurs le compilateur a dû t'indiquer qu'il y a un problème.
    On peut plutôt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    	friend std::ostream&  operator<<(std::ostream& os, Kurve const& k) {
    		auto  it = k.kur.begin();
    		while ( it != k.kur.end() )
    			os << *it++ << std::endl;
    		return  os; 
    	}

  11. #11
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut Merci de votre aide
    [Merci beaucoup Dalfab, vous avez raison

  12. #12
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 144
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 144
    Points : 1 676
    Points
    1 676
    Par défaut
    Corrige quand même les points que je t'ai indiqué.
    En l'état, ton code est tout sauf correcte.

  13. #13
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut tangente à une parabole
    Merci deedolith, tout cela est pratique, maintenant j'ai une autre question, une équation quadratique peut avoir deux solutions, je cherche une tangente à une parabole à partir d'un point du plan.

  14. #14
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9

  15. #15
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 144
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 144
    Points : 1 676
    Points
    1 676
    Par défaut
    Crée un autre sujet,
    parce que ca n'a rien a voir avec l'intersection de 2 segments.

    Et comme d'hab, expose nous ce que tu as déja fait et ce qui te pose problème (on ne fera pas le truc à ta place).

  16. #16
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut
    https://www.geogebra.org/calculator/qrs6dn8v Merci deedolit, Je vais vous montrer le code bientôt.

  17. #17
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut Merci deedelith:Le point de contact de la tangente1 et de la parabole & Point d'intersection des deux lignes d
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    //	https://www.arndt-bruenner.de/mathe/10/parabeltangente.htm#:~:text=Somit%20ergibt%20sich%20f%C3%BCr%20die%20Tangente%20an%20die,jeden%20Punkt%20x%20durch%202ax%20%2B%20b%20gegeben.
     
    #include <iostream>
    #include <string>
    #include <vector>
    #include <iterator>
    #include <initializer_list>
     
    class Point
    {
    private:
    	float mX, mY;
    public:
    	Point() :
    		mX{ 0 },
    		mY{ 0 }
    	{}
    	Point(float x, float y) :
    		mX{ x },
    		mY{ y }
    	{}
    	Point(Point const& p) :
    		mX{ p.mX },
    		mY{ p.mY }
    	{}
    	Point& operator=(Point const& rhs) {
    		mX = rhs.mX;
    		mY = rhs.mY;
    		return *this;
    	}
    	float x() const
    	{
    		return mX;
    	}
    	float y() const
    	{
    		return mY;
    	}
    	void set_x(float xx)
    	{
    		mX = xx;
    	}
    	void set_y(float yy)
    	{
    		mY = yy;
    	}
    	friend std::ostream&
    		operator<<(std::ostream& os, Point const& p) {
    		return os << "x = " << p.mX << " y = " << p.mY;
    	}
    };
    class Kurve : public Point {
    public:
    	std::vector<Point> kur;
     
     
    public:
    	Kurve(std::initializer_list<Point> liste) : kur{ liste } {}
    	Kurve(Point p) {
    		kur.push_back(p);
    	}
     
    	std::vector<Point>& get_kur() {
    		return kur;
    	}
    };
     
     
    class Segment
    {
    private:
    	Point mA, mB;
    public:
    	Segment(Point A, Point B) :
    		mA{ A }, mB{ B }
    	{}
    	float A() const		// Coefficient A: y = Ax + B
    	{
    		return (mA.y() - mB.y()) / (mA.x() - mB.x());
    		// source: https://calculis.net/droite
    					// A completer
    	}
    	float B() const		// Coefficient B: y = Ax + B
    	{
    		return mA.y() - A() * mA.x();
    		// source: https://calculis.net/droite
    					// A completer
    	}
    	Point intersection(Segment const& other)
    	{
    		float x = (other.B() - B()) / (A() - other.A());
    		// source: https://calculis.net/intersection
    		// A completer
     
    		// A completer
    		return Point{ x , A() * x + B() };
    	}
    	std::string equation() const
    	{
    		return "y = " + std::to_string(A()) + "x + " + std::to_string(B());
    	}
    };
    int main() {
    	Point poiA(0, 0);
    	Point poiB(2, pow(2, 2));
     
     
    	Kurve parabole({ 0,0 });
    	for (float i = 0; i < 100; i++)
    		parabole.kur.push_back({ i * 0.1f,pow(i * 0.1f,2.0f) });
     
    	float xQ, yQ;
    	std::cout << "Veuillez calculer le point à partir duquel la tangente est calculée sur la parabole:   " << std::endl;
    	std::cout << "S’il vous plaît x: ";
    	std::cin >> xQ;
     
    	std::cout << std::endl;
    	std::cout << "S’il vous plaît y: ";
    	std::cin >> yQ;
     
    	std::cout << std::endl;
     
     
    	Kurve parabole_Bsp_1({ 0.0f,0.0f });
    	for (float i = -30.0f; i < 100; i++) {
    		parabole_Bsp_1.kur.push_back({ i * 0.1f, -3 * pow(i * 0.1f,2.0f) + 2*i*0.1f + 1 });
    	}
     
    	// Calculer la tangente , Point Q connu Q(-1,-1), La tangente a une forme y = Ax + B , Parabole f(x) = -3x^2 + 2x +1
    	// Point de contact T(xT,yT) , yT = A*xT + B, A est tangente de l’angle de la tangente A = f'(x) = -6x + 2
     
     
     
    	// Parabel yT = -3xT^2 + 2xT +1  ; Tangente yT = (-6xT +2) xT + B
     
     
     
     
    	//  https://www.youtube.com/watch?v=ql_w5paclOs
     
    	// f(x)Tangente = f(x)Parabel
    	// -3x^2 +2x + 1 = AxO + B = (-6x + 2) * xQ + B
    	// -3 * x^2  + 2 * x * xQ + 1 = -6 * x^2 + 2x + B 
    	// 3 *  x^2 - 6 * xQ * x + 2 * xQ - yQ + 1 = 0
     
     
     
    	float a = 3;
     
    	float b = -6 * xQ;
     
    	float c =  2 * xQ - yQ + 1;
     
    	float xT1 = ((-1) * b + std::sqrt(pow(b, 2.0f) - 4 * a * c)) / (2 * a);
     
    	float xT2 = ((-1) * b - std::sqrt(pow(b, 2.0f) - 4 * a * c)) / (2 * a);
     
    	float A1 = -6.0f * xT1 + 2;
    	float A2 = -6.0f * xT2 + 2;
    	float B1 = yQ - A1 * xQ;    
    	float B2 = yQ - A2 * xQ;
     
    	float yT1 = A1 * xT1 + B1;
    	float yT2 = A2 * xT2 + B2;
     
    	Point Q(xQ, yQ);
    	Point T1(xT1, yT1);
    	Point T2(xT2, yT2);
    	Segment tangente1(Q, T1);
    	std::cout << tangente1.equation() << std::endl;
    	Segment tangente2(Q, T2);
    	std::cout << tangente2.equation() << std::endl;
     
     
     
    	std::cout << "Le point de contact de la tangente1 et de la parabole est "
    		<< "T1(" << xT1 << ", " << yT1 << ")" << std::endl;
    	std::cout << "Le point de contact de la tangente1 et de la parabole est "
    		<< "T2(" << xT2 << ", " << yT2 << ")" << std::endl;
     
     
    	auto it = parabole_Bsp_1.kur.begin();
    	while (it != parabole_Bsp_1.kur.end()) {
    		std::cout << "parabole(x, y) " << *it++ << std::endl;
     
    	}
    	std::cout << "Hiperbole " << std::endl;
    	Kurve hiperbole({ 0,0 });
    	for (float i = 0; i < 100; i++)
    		hiperbole.kur.push_back({ i * 0.1f,pow(i * 0.1f,.5f) });
     
     
     
     
     
    	auto it_h = hiperbole.kur.begin();
    	while (it_h != hiperbole.kur.end()) {
    		std::cout << *it_h++ << std::endl;
     
    	}
     
     
    	Point pA(3.5f, 4.0f);
    	Point pB(-4.0f, 2.0f);
    	Point pC(2.0f, -2.0f);
    	Point pD(-2.0f, 5.0f);
    	std::cout << "Point d'intersection des deux lignes droites: " << std::endl;
    	Segment Line1(pA, pB);
    	std::cout << Line1.equation() << std::endl;
    	Segment Line2(pC, pD);
    	std::cout << Line2.equation() << std::endl;
     
    	std::cout << Line1.intersection(Line2);	// Point d'intersection des deux lignes droites
    }

  18. #18
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 144
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 144
    Points : 1 676
    Points
    1 676
    Par défaut
    Je n'ai pas tout regardé,
    mais tu fait toujours les même erreurs.
    Pourquoi cette aberration ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    class Kurve : public Point

  19. #19
    Inactif  
    Homme Profil pro
    Oui
    Inscrit en
    Décembre 2022
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Autriche

    Informations professionnelles :
    Activité : Oui

    Informations forums :
    Inscription : Décembre 2022
    Messages : 36
    Points : 9
    Points
    9
    Par défaut class Point
    Merci deedolit, Je dois encore apprendre à hériter

  20. #20
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    1 144
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 144
    Points : 1 676
    Points
    1 676
    Par défaut
    Je pense que tu voit les classes comme des conteneurs de données.
    Ce n'est pas le cas, une classe est un fournisseur de service, elle représente "quelque chose" et les comportements qui lui sont associés. Les données ne sont que des détails d'implémentation.

    Une classe fille qui hérite d'une classe mère implique que la classe fille obtiens les mêmes comportements que la classe mère.

    Il y a également une notion à bien comprendre:
    L'héritage introduit une relation forte entre les classes: On dit que la classe fille est une classe mère.
    Par exemple: un Animal (classe fille) est un Mammifère (classe Mère).
    Attention: L'inverse n'est pas vrai.

    Dans ton cas:
    Un segment est constitué de 2 points (en français dans le texte).
    La relation est constitué de (aussi appelé agrégation) se traduit par la déclaration des variables membre, aucun héritage n'intervient de ce processus.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Attribut name est incorrect
    Par FullOver dans le forum Struts 1
    Réponses: 5
    Dernier message: 02/05/2008, 09h58
  2. JasperException: L'attribut name est incorrect
    Par fk04 dans le forum Struts 1
    Réponses: 2
    Dernier message: 13/05/2007, 13h07
  3. Réponses: 4
    Dernier message: 26/08/2006, 02h01
  4. [C#] [1.1] Le format de la chaîne d'entrée est incorrect
    Par Sup@Lou dans le forum Windows Forms
    Réponses: 2
    Dernier message: 08/08/2006, 10h01
  5. [PHPMyAdmin] "Le nom de répertoire est incorrect"
    Par DavidDeTroyes dans le forum Installation
    Réponses: 3
    Dernier message: 13/03/2006, 17h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo