poj1269---计算几何(向量叉积)

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

int judge_3(int x1,int y1,int x2,int y2,int x3,int y3){
	return (x2-x3)*(y1-y3)-(x1-x3)*(y2-y3);
}
int judge_4(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
	return (x2-x1)*(y3-y4)-(x3-x4)*(y2-y1);
}
int main(){
	int t,x1,x2,x3,x4,y1,y2,y3,y4;
	cin>>t;
	printf("INTERSECTING LINES OUTPUT\n");
	while(t--){
		cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		if(judge_4(x1,y1,x2,y2,x3,y3,x4,y4)==0){//满足平行 
			if(judge_3(x1,y1,x2,y2,x4,y4)==0){//满足共线 
				printf("LINE\n");
			}
			else printf("NONE\n");//仅平行 
		}
		else{//相交 
			//解方程 
			double a1=y1-y2;
			double b1=x2-x1;
			double c1=x1*y2-x2*y1;
			double a2=y3-y4;
			double b2=x4-x3;
			double c2=x3*y4-x4*y3;
			double x0=(c2*b1-c1*b2)/(a1*b2-a2*b1);
			double y0=(c1*a2-c2*a1)/(a1*b2-a2*b1);
			printf("POINT %.2f %.2f\n",x0,y0);
		}
	} 
	printf("END OF OUTPUT\n");
	return 0;
}
//            /\       |  /  |**、
//			 /  \      | /   |   \
//			/    \     |/    |   /  _____                      ____   |  /
//		   /------\    |\    |__/  /     \  \      /\      /  /    \  | /
//		  /        \   | \   |    /       \  \    /  \    /  /______\ |/
//		 /          \  |  \  |    \       /   \  /    \  /   \        |
//      /            \ |   \ |     \_____/     \/      \/     \_____  |
/**
 *        ┏┓    ┏┓
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃  
 *        ┃   ━    ┃
 *        ┃ >   < ┃
 *        ┃       ┃
 *        ┃... ⌒ ...  ┃
 *        ┃       ┃
 *        ┗━┓   ┏━┛
 *          ┃   ┃ Code is far away from bug with the animal protecting          
 *          ┃   ┃   神兽保佑,代码无bug
 *          ┃   ┃           
 *          ┃   ┃        
 *          ┃   ┃
 *          ┃   ┃           
 *          ┃   ┗━━━┓
 *          ┃       ┣┓
 *          ┃       ┏┛
 *          ┗┓┓┏━┳┓┏┛
 *           ┃┫┫ ┃┫┫
 *           ┗┻┛ ┗┻┛
 */
// warm heart, wagging tail,and a smile just for you!
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \\  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//
发布了186 篇原创文章 · 获赞 38 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43746332/article/details/104132681
今日推荐