#include <iostream> using namespace std; typedef struct //直线方程 { double a; double b; double c; }Tline; typedef struct //点坐标 { double x; double y; }Tpoint; //根据两点坐标求出直线方程 A(x1,y1) B(x2,y2) //方程为(y2-y1)x+(x1-x2)y+2x1*y1-x1*y2+x2*y1; Tline lineFormSegment(Tpoint p1,Tpoint p2) { Tline temp; temp.a = p2.y-p1.y; temp.b = p1.x-p2.x; temp.c = 2*p1.x*p1.y-p1.x*p2.y*p2.x*p1.y; return temp; } bool IsOnline(Tpoint p,Tline line) { return line.a*p.x+line.b*p.y+line.c==0; } int main() { Tpoint p1; p1.x=0; p1.y=0; Tpoint p2; p2.x=0; p2.y=1; Tpoint p3; p3.x=2; p3.y=2; Tline line =lineFormSegment(p1,p3); if(IsOnline(p2,line))printf("online/n"); return 0; }