Advertisement
dream_4ild

9-И-2 ex.3

Dec 10th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Nov 19 20:58:30 2020
  4.  
  5. @author: Sergey
  6. """
  7. import math
  8.  
  9.  
  10. def left_or_right(x,y,k):
  11.     x1=0
  12.     y1=0
  13.     x2=1
  14.     y2=k*x2
  15.     D = (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1)
  16.     if D > 0:
  17.         ans='right'
  18.     elif D < 0:
  19.         ans='left'
  20.     elif D == 0:
  21.         ans='on'
  22.     return ans
  23.  
  24. def len_h(x,y,k):
  25.     if (left_or_right(x,y,k) == 'left') or(left_or_right(x,y,k) == 'right'):
  26.         x1=y/k
  27.         y1=k*x
  28.         a=x1-x
  29.         b=y1-y
  30.         c=math.sqrt((a**2)+(b**2))
  31.         ac=(a**2)/c
  32.         bc=c-ac
  33.         h=math.sqrt(ac*bc)
  34.     else:
  35.         h=-1
  36.     return h
  37.        
  38.  
  39. x1,y1,x2,y2,x3,y3,k=float(input()),float(input()),float(input()),float(input()),float(input()),float(input()),float(input())
  40.  
  41. a=[len_h(x1,y1,k),len_h(x2,y2,k),len_h(x3,y3,k)]
  42. print(a)
  43. ans=10**10
  44. if min(a)==-1:
  45.     print(a.index(-1)+1)
  46. else:
  47.     print(a.index(min(a))+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement