R
R
RED1cat2020-10-20 13:47:54
Python
RED1cat, 2020-10-20 13:47:54

Determine if (x,y) belongs to the shaded area?

5f8ec02804e2d934340985.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
twobomb, 2020-10-20
@twobomb

If it is possible to represent this figure as a polygon, then it is possible like this
. And if not, then we represent the upper part as a polygon, and the lower part is checked as an occurrence in a circle , but if the Y coordinate of the point is above the center of the circle, then false
PS An example of the second option on js

S
StyleBender, 2020-10-20
@StyleBender

I think that this figure can be quite simply described by a set of functions: two straight lines and a lower arc of a circle. More in code:

import math


def f1(x):
    return x + 1


def f2(x):
    return -x + 1


# x^2 + y^2 = r^2 => y = sqrt(r^2 - x^2)
def c(x, r=1):
    return  -math.sqrt(r**2 - x**2)


x = float(input("Enter x: "))
y = float(input("Enter y: "))

if y <= f1(x) and y <= f2(x) and y >= c(x):
    print("hit")
else:
    print("missed")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question