• 求两直线交点坐标


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

    代码:

    #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
    ",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;
    }
    
    由于博主比较菜,所以有很多东西待学习,大部分文章会持续更新,另外如果有出错或者不周之处,欢迎大家在评论中指出!
  • 相关阅读:
    C# 生成随机索引列表
    QQ音乐MP3下载
    微信Dat文件解码
    C#工作常用关键字
    C#左移运算符
    C#中datatable操作
    html 显示 pdf
    framework7 下拉刷新、无限滚动
    framework7 总结之前遇到的问题和踩过的坑
    HTML 引用大全
  • 原文地址:https://www.cnblogs.com/With-penguin/p/13228509.html
Copyright © 2020-2023  润新知