高中的几何代数的综合运用
思路看代码吧:# -*- coding: utf-8 -*-
"""
Created on Sat Jan 7 11:37:42 2017
@author: Jerry Xu
"""
def linesolve(k,b,p):
x1 = (-k*b + (100*k*k-4*b*b+400)**0.5)/(4+k*k)
y1 = k*x1 + b
x2 = (-k*b - (100*k*k-4*b*b+400)**0.5)/(4+k*k)
y2 = k*x2 + b
if abs(x1-p[0]) < 0.001 and abs(y1-p[1]) < 0.001:
return x2,y2
else:
return x1,y1
#初始化:
# 入射方程:y = k*x + b, 入射点p
k,b = -19.7/1.4,10.1
p = (0,10.1)
c = 0
while not (-0.01<=linesolve(k,b,p)[0]<=0.01 and linesolve(k,b,p)[1]>=(100-4*0.01*0.01)**0.5):
c += 1
point = linesolve(k,b,p) #直线与椭圆的另一焦点
m = -4*point[0]/point[1] #法线斜率
n = point[1] -m*point[0]
# 法线方程: y = m*x + n
# 入射点的镜像点坐标:(qx,qy)
qx = (-m*m*p[0]-2*m*n+2*m*p[1]+p[0])/(m*m+1)
qy = m*qx+p[0]*m+2*n-p[1]
# 反射方程:y = k*x + b, 反射射点p,也是下一轮的入射方程和入射点
k = (qy-point[1])/(qx-point[0])
b = qy - k*qx
p = point
print (c)
输出:
354 |