根据四个点求两条直线的交点

编程入门 行业动态 更新时间:2024-10-28 13:20:12

根据四个点求两条直线的<a href=https://www.elefans.com/category/jswz/34/1768934.html style=交点"/>

根据四个点求两条直线的交点

linear.h头文件的内容

#ifndef LINEAREQUATION_H
#define LINEAREQUATION_H#include<iostream>
using namespace std;class LinearEquation
{
private:double a, b, c, d, e, f;//six variables for linear equationpublic://constructor for the six variablesLinearEquation(double theA, double theB, double theC, double theD, double theE, double theF){a = theA;b = theB;c = theC;d = theD;e = theE;f = theF;}//constructor for intersectionLinearEquation(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4){//For first linea = y2 - y1;b = x1 - x2;e = (a * x1) + (b * y1);//for second linec = y4 - y3;d = x3 - x4;f = (c * x3) + (d * y3);}//six "getter" functions, one for each variabledouble getA() { return a; }double getB() { return b; }double getC() { return c; }double getD() { return d; }double getE() { return e; }double getF() { return f; }//tells whether or not the equation is solvablebool isSolvable(){if ((a * d) == (b * c)){return false;}else{return true;}};//"getter" function that returns xdouble getX(){double first = e * d;double second = b * f;double sub = first - second;double third = a * d;double fourth = b * c;double subTwo = third - fourth;double x = sub / subTwo;//double x = ((e * d) - (b * f)) / ((a * d) - (b * c));return x;}//"getter" function that returns ydouble getY(){double y = ((a * f) - (e * c)) / ((a * d) - (b * c));return y;}
};#endif

交点jiaodian.cpp文件:

#include<iostream>
#include"linear.h"
using namespace std;//分为两组,第一组为x1,y1与x2,y2;另一组为x3y3,x4y4
int main()
{double x1 = 1, y1 = 2, x2 = 4, y2 = 2, x3 = 2, y3 = 1, x4 = 2, y4 = 4;LinearEquation twoLines(x1, y1, x2, y2, x3, y3, x4, y4);if (twoLines.isSolvable()){cout << "The intersection is " << twoLines.getX() << "," << twoLines.getY() << endl;}else{cout << "These lines do not intersect." << endl;}return 0;
}

更多推荐

根据四个点求两条直线的交点

本文发布于:2024-02-24 18:15:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1696237.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:交点   两条   直线

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!