参考:http://blog.csdn.net/abcjennifer/article/details/7584628
# -*- coding: utf-8 -*-
class Point(object):
x =0
y= 0
# 定义构造方法
def __init__(self, x=0, y=0):
self.x = x
self.y = y
class Line(object):
# a=0
# b=0
# c=0
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
def GetLinePara(line):
line.a =line.p1.y - line.p2.y;
line.b = line.p2.x - line.p1.x;
line.c = line.p1.x *line.p2.y - line.p2.x * line.p1.y;
def GetCrossPoint(l1,l2):
GetLinePara(l1);
GetLinePara(l2);
d = l1.a * l2.b - l2.a * l1.b
p=Point()
p.x = (l1.b * l2.c - l2.b * l1.c)*1.0 / d
p.y = (l1.c * l2.a - l2.c * l1.a)*1.0 / d
return p;
p1=Point(1,1)
p2=Point(3,3)
line1=Line(p1,p2)
p3=Point(2,3.1)
p4=Point(3.1,2)
line2=Line(p3,p4)
Pc = GetCrossPoint(line1,line2);
print("Cross point:", Pc.x, Pc.y);
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有