Python Forum
Intersection of a triangle and a circle
Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Intersection of a triangle and a circle
#1
Determine whether a common point the two flat shapes: triangle, given
the coordinates of its vertices and the circle with the given radius and center at the origin.

I am from Russia and i cant get help in russian community help please if u understand what i whrite

Thats what i can but its not always true

from math import sqrt 

print("Введите координаты первой точки через пробел: ")

x1, y1 = (int(i) for i in input().split())

print("Введите координаты второй точки через пробел: ")

x2, y2 = (int(i) for i in input().split())

print("Введите координаты третьей точки через пробел: ")

x3, y3 = (int(i) for i in input().split())

print("Введите радиус окружности: ")

R = int(input())

rast1 = abs(x1*y2 - x2*y1) / sqrt((y1-y2)**2 + (x2-x1)**2)

rast2 = abs(x1*y3 - x2*y1) / sqrt((y1-y3)**2 + (x3-x1)**2)

rast3 = abs(x3*y2 - x2*y1) / sqrt((y3-y2)**2 + (x2-x3)**2)
 
if sqrt(x1 ** 2 + y1 ** 2)<=R:

    print("YES")

elif sqrt(x2 ** 2 + y2 ** 2)<=R:

        print("YES")

elif sqrt(x3 ** 2 + y3 ** 2)<=R:

        print("YES")

if rast1 <= R and ( abs(y1) < R or abs(y2) < R ) and (abs(x1) < R or abs(x2) < R):
                                                                                                                                                                            
    print("YES")

if rast2 <= R and ( abs(y1) < R or abs(y3) < R ) and (abs(x1) < R or abs(x3) < R):

    print("YES")

if rast3 <= R and ( abs(y3) < R or abs(y2) < R ) and (abs(x3) < R or abs(x2) < R):

    print("YES")

else:

    print("NO")
Translation
from math import sqrt
 
print ("Enter the coordinates of the first point separated by a space:")
 
x1, y1 = (int (i) for i in input (). split ())
 
print ("Enter the coordinates of the second point separated by a space:")
 
x2, y2 = (int (i) for i in input (). split ())
 
print ("Enter the coordinates of the third point separated by a space:")
 
x3, y3 = (int (i) for i in input (). split ())
 
print ("Enter the radius of the circle:")
 
R = int (input ())
 
rast1 = abs (x1 * y2 - x2 * y1) / sqrt ((y1-y2) ** 2 + (x2-x1) ** 2)
 
rast2 = abs (x1 * y3 - x2 * y1) / sqrt ((y1-y3) ** 2 + (x3-x1) ** 2)
 
rast3 = abs (x3 * y2 - x2 * y1) / sqrt ((y3-y2) ** 2 + (x2-x3) ** 2)
  
if sqrt (x1 ** 2 + y1 ** 2) <= R:
 
    print ("YES")
 
elif sqrt (x2 ** 2 + y2 ** 2) <= R:
 
        print ("YES")
 
elif sqrt (x3 ** 2 + y3 ** 2) <= R:
 
        print ("YES")
 
if rast1 <= R and (abs (y1) <R or abs (y2) <R) and (abs (x1) <R or abs (x2) <R):
                                                                                                                                                                             
    print ("YES")
 
if rast2 <= R and (abs (y1) <R or abs (y3) <R) and (abs (x1) <R or abs (x3) <R):
 
    print ("YES")
 
if rast3 <= R and (abs (y3) <R or abs (y2) <R) and (abs (x3) <R or abs (x2) <R):
 
    print ("YES")
 
else:
 
    print ("NO")
Reply
#2
We could help better, if your program comments are in english.
Reply
#3
My russian is becoming rusty, but my understanding is that user inputs are asked with following texts:

"Enter the coordinates of the first/second/third point separated by a space" and "Enter the radius of the circle"
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
Assuming the task is to determine
if a triangle-shape and a circle-shape have at least one common point.

I think that rast2 and rast3 are wrong:

They should be:
# shortest distance between origin and line given by two points
rast1 = abs(x1*y2 - x2*y1) / sqrt((y1-y2)**2 + (x2-x1)**2)
rast2 = abs(x1*y3 - x3*y1) / sqrt((y1-y3)**2 + (x3-x1)**2)
rast3 = abs(x3*y2 - x3*y2) / sqrt((y3-y2)**2 + (x2-x3)**2)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How Can I Draw Circle With Turtle İn Python ? mdm 2 2,699 Jun-03-2021, 02:07 PM
Last Post: DPaul
  How to write a recursion syntax for Sierpinski triangle using numpy? Bolzano 2 3,804 Apr-03-2021, 06:11 AM
Last Post: SheeppOSU
Photo I need help with a circle random color code and error Vxploit 4 2,955 Mar-21-2021, 07:23 PM
Last Post: jefsummers
  Turtle circle Fabio87 3 2,424 Dec-17-2020, 10:52 PM
Last Post: Fabio87
  Print user input into triangle djtjhokie 1 2,342 Nov-07-2020, 07:01 PM
Last Post: buran
  Intersection Kimberley100 6 2,808 Oct-10-2020, 08:53 PM
Last Post: Kimberley100
  Tkinter - The Reuleaux Triangle andrewapk 1 1,875 Oct-06-2020, 09:01 PM
Last Post: deanhystad
  Python - networkx - Triangle inequality - Graph Nick_A 0 2,054 Sep-11-2020, 04:29 PM
Last Post: Nick_A
  Calculate area of a circle pythonuser1 20 6,836 Apr-15-2020, 03:18 AM
Last Post: Skaperen
  Triangle function program m8jorp8yne 2 8,797 Dec-13-2019, 05:24 PM
Last Post: Clunk_Head

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020