欧拉计划 #246:切线之间的椭圆角的切线 [英] Project Euler #246: Tangents to an ellipse Angle between Tangents

查看:29
本文介绍了欧拉计划 #246:切线之间的椭圆角的切线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了原点转移并试图解决

输入

64817 64819 11420330 1

输出

1.5 1.118033988749895 #椭圆a、b的值88.09084756700362 #给定的角度0 2 84.26082952273322 # x、y 和角度0 3 56.632987030768250 4 42.6679254941083740 5 34.216051131298260 6 28.5526373601823021 1 132.13041476136661 2 105.376759904052051 3 126.936189893419621 4 138.996800402486431 5 146.681393159999351 6 151.982299198372122 0 99.594068226860432 1 70.402516287008522 2 123.92838964927597 #图中56.0716为补角2 3 135.07957757388362 4 143.165216347584822 5 149.054610641304752 6 153.445704049726663 0 133.432536557789773 1 45.16851797042273 2 138.680628321701933 3 143.54418030200863 4 148.19667608908153 5 152.192823981521263 6 155.498124370897274 0 146.44269023807934 1 33.1507727639423144 2 148.189187529128224 3 150.35259871745344 4 152.89718759240724 5 155.437530938487534 6 157.774243824591935 0 153.615670250592075 1 26.216167612764485 2 154.364037753896985 3 155.41351971867445 4 156.823142645185475 5 158.405848221231965 6 160.0051145189886 0 158.213210701738156 1 21.701509698418796 2 158.593340155117466 3 159.15282828194986 4 159.96643520576846 5 160.960548196653266 6 162.04466838669927

代码

from math import atan从数学导入 acos从数学导入学位从数学导入 atan2从数学导入 sqrt从运营商进口 gt从操作符导入 abs类 P_test():def __init__(self,x,y,a,b):self.x, self.y, self.a, self.b = x, y, a, bdef Region(self): # 测试点(x,y)是否在椭圆区域之外如果 (self.x/self.a)**2 + (self.y/self.b)**2 > 1:返回 1def T_angle(self): # 返回切线之间的角度但不是预期的 无x, y = self.x, self.yA, B, C = self.a**2-self.x**2, 2*self.x*self.y, self.b**2-self.y**2D = sqrt(B**2-4*A*C)m1, m2 = (-B+D)/(2*A), (-B-D)/(2*A)alpha1 = 度数(acos(1/(sqrt(1+m1**2))))alpha2 = 度数(acos(1/(sqrt(1+m2**2))))如果 x*y: 返回 180 度(abs(atan2(y,y/m1)-atan2(y,y/m2)))返回 180-abs(alpha2)-abs(alpha1)类数据源():def __init__(self, cordinate, radius, pq):self.xy, self.r, self.pq = 坐标、半径、pqdef a_b_of_ellipse(self):x1, x2, y, r = self.xy[0], self.xy[1], self.xy[2], self.rH, K = x1 + (x2-x1)/2, ymx, 我 = x1-H, y-Kgx, gy = x2-H, y-Kae = (mx-gx)/2a =gx + (r-(x2-x1))/2b = sqrt(a**2-ae**2)返回 a, bdef G_angle(self):返回度数(atan(self.pq[0]/self.pq[1]))xy_cord = list(map(int, input().split()))半径 = 整数(输入())pq = list(map(int, input().split()))r1 = 数据源(xy_cord,半径,pq)aa, bb, G = r1.a_b_of_ellipse()[0], r1.a_b_of_ellipse()[1], r1.G_angle()打印(aa,bb);打印(G)对于范围内的 x(0,7):对于范围内的 y(0,7):r2 = P_test(x,y,aa,bb)如果 r2.Region():打印(x,y,r2.T_angle())

我怎样才能找到只有阿尔法角

解决方案

但是您可以计算切点,因此无需使用斜率 - 只需从三角形 TP1-D-TP2 中获取 alpha

I used shift of origin and tried to solve problem

My Similar question on StackOverflow

and now that ellipse after shift of origin has equation (x/a)^2+(y/b)^2=1 so after condition of tangency to ellipse (am)^2+b^2=c^2 where c = y0-mx0 solved for m where D = (x0, y0) is variable point in only +quadrant as ellipse is symmetrical about axes number of lattice points for which the angle between tangents is greater than given angle will be multiplied by 2 if point D is on either axes else with 4

But now I'm unable to find the expected angle α which to this contrast program may result in (180-α) or (90-α) or whatever but is not giving α always

Input

64817 64819 11420
3
30 1

Output

1.5 1.118033988749895      #values of a, b of ellipse
88.09084756700362          #Given angle
0 2 84.26082952273322      # x, y, and angle
0 3 56.63298703076825
0 4 42.667925494108374
0 5 34.21605113129826
0 6 28.552637360182302
1 1 132.1304147613666
1 2 105.37675990405205
1 3 126.93618989341962
1 4 138.99680040248643
1 5 146.68139315999935
1 6 151.98229919837212
2 0 99.59406822686043
2 1 70.40251628700852
2 2 123.92838964927597      #In figure it is 56.0716 while it's supplementary angle
2 3 135.0795775738836
2 4 143.16521634758482
2 5 149.05461064130475
2 6 153.44570404972666
3 0 133.43253655778977
3 1 45.1685179704227
3 2 138.68062832170193
3 3 143.5441803020086
3 4 148.1966760890815
3 5 152.19282398152126
3 6 155.49812437089727
4 0 146.4426902380793
4 1 33.150772763942314
4 2 148.18918752912822
4 3 150.3525987174534
4 4 152.8971875924072
4 5 155.43753093848753
4 6 157.77424382459193
5 0 153.61567025059207
5 1 26.21616761276448
5 2 154.36403775389698
5 3 155.4135197186744
5 4 156.82314264518547
5 5 158.40584822123196
5 6 160.005114518988
6 0 158.21321070173815
6 1 21.70150969841879
6 2 158.59334015511746
6 3 159.1528282819498
6 4 159.9664352057684
6 5 160.96054819665326
6 6 162.04466838669927

Code

from math import atan
from math import acos
from math import degrees
from math import atan2
from math import sqrt
from operator import gt
from operator import abs
class P_test():
    def __init__(self,x,y,a,b):
        self.x, self.y, self.a, self.b = x, y, a, b
    
    def Region(self):                # Tests if point(x,y) is out of region of ellipse
        if (self.x/self.a)**2 + (self.y/self.b)**2 >1:
            return 1
    
    def T_angle(self):              # Returns angle between tangents but not expected None
        x, y = self.x, self.y
        A, B , C = self.a**2-self.x**2, 2*self.x*self.y, self.b**2-self.y**2
        D = sqrt(B**2-4*A*C)
        m1, m2 = (-B+D)/(2*A), (-B-D)/(2*A)
        alpha1 = degrees(acos(1/(sqrt(1+m1**2))))        
        alpha2 = degrees(acos(1/(sqrt(1+m2**2))))
        if x*y: return 180-degrees(abs(atan2(y,y/m1)-atan2(y,y/m2)))
        return 180-abs(alpha2)-abs(alpha1)
    
class Datasource():
    def __init__(self, cordinate, radius, pq):
        self.xy, self.r, self.pq = cordinate, radius, pq
    
    def a_b_of_ellipse(self):
        x1, x2, y, r = self.xy[0], self.xy[1], self.xy[2], self.r
        H, K = x1 + (x2-x1)/2, y
        mx, my = x1-H, y-K
        gx, gy = x2-H, y-K
        ae = (mx-gx)/2
        a =gx + (r-(x2-x1))/2
        b = sqrt(a**2-ae**2)
        return a, b
    
    def G_angle(self):
        return degrees(atan(self.pq[0]/self.pq[1]))
    
    
    
xy_cord = list(map(int, input().split()))
radius = int(input())
pq = list(map(int, input().split()))
r1 = Datasource(xy_cord, radius, pq)
aa, bb, G = r1.a_b_of_ellipse()[0], r1.a_b_of_ellipse()[1], r1.G_angle()
print(aa, bb); print(G)
for x in range(0,7):
    for y in range(0,7):
        r2 = P_test(x,y,aa,bb)
        if r2.Region():
            print(x,y,r2.T_angle())

How can I find Only Alpha Angle

解决方案

But you can calculate tangent points, so no need in using slopes - just get alpha from triangle TP1-D-TP2

这篇关于欧拉计划 #246:切线之间的椭圆角的切线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆