首页 > 其他 > 详细

求两直线交点坐标

时间:2020-07-03 11:02:27      阅读:65      评论:0      收藏:0      [点我收藏+]

使用面积法与矢量叉积即可。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

struct Point
{
	double x,y;
	
	Point() {}
	Point(double X,double Y) :x(X),y(Y) {}
	Point operator + (const Point a)const { return Point(a.x+x,a.y+y); }
	Point operator - (const Point a)const { return Point(x-a.x,y-a.y); }
	Point operator * (const double a)const { return Point(x*a,y*a); }
	double operator * (const Point a)const { return x*a.y-y*a.x; }
	void read() { scanf("%lf %lf",&x,&y); }
	void print() { printf("%lf %lf\n",x,y); }
}A,B,C,D;

Point cross(Point p1,Point v1,Point p2,Point v2)
{
	double t=((p2-p1)*v2)/(v1*v2);
	return p1+v1*t;
}

int main()
{
	A.read(),B.read(),C.read(),D.read();
	cross(A,B-A,C,D-C).print();
	return 0;
}

求两直线交点坐标

原文:https://www.cnblogs.com/With-penguin/p/13228509.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!