QUESTION

Text
Image


H 2. Do They Belong? A triangle formed by the three points $a(x 1, y 1), b(x 2, y 2)$ and $c(x 3, y 3)$ is ALL (i) 1 a non-degenerate triangle if the following rules are respected $(/ a b /$ is the length of the line between points $a$ and $b$ ): $-|a b|+|b c|>|a c|$ - $|b c|+|a c|>|a b|$ - $|a b|+|a c|>|b c|$ A point belongs to a triangle if it lies somewhere on or inside the triangle. Given two points $p=(x p, y p)$ and $q=(x q, y q)$, return the 2 correct scenario number: - 0 : If the triangle abc does not form a valid non-degenerate triangle. - 1: If point $p$ belongs to the triangle but point $q$ does not. - 2 : If point $q$ belongs to the triangle but point $p$ does not. - 3: If both points $p$ and $q$ belong to the triangle. - 4: If neither point $p$ nor point $q$ belong to the triangle. Example $1>\# ! /$ bin/python $3 \cdots$ 10 $\#$ \# Complete the 'pointsBelong' function below. $\#$ \# The function is expected to return an INTEGER. \# The function accepts following parameters: \# 1. INTEGER $\times 1$ \# 2. INTEGER y 1 \# 3. INTEGER $\times 2$ \# 4. INTEGER y2 \# 5. INTEGER $\times 3$ \# 6. INTEGER y3 \# 7. INTEGER xp \# 8. INTEGER yp \# 9. INTEGER $\times q$ \# 10. INTEGER yq \# def pointsBelong $(x 1, y 1, x 2, y 2, x 3, y 3, x p, y p, x q, y q)$ : \# Write your code here if __name__- = '_-main__' : Line: 29 Col: 27


Example $1=$ $a(x 1, y 1):$ $(2,2)$ $2=$ $b(x 2, y 2)$ : $(7,2)$ $3=$ $c(x 3, y 3)$ : $(5,4)$ $p=p(x p$, $y p):(4,3)$ $q=q(x q$, $y q):(7,4)$


First, the triangle abc forms a valid non-degenerate triangle - $|\mathrm{ab}|=7-2=$ 5. $|\mathrm{bc}|=\operatorname{sqrt}\left((7-5)^{2}+(4-2)^{2}\right)=\operatorname{sqrt}\left(2^{2}+2^{2}\right)=\operatorname{sqrt}(8)=$ 2.82. $|\mathrm{ac}|=\operatorname{sqrt}\left((5-2)^{2}+(4-2)^{2}\right)=\left(3^{2+} 2^{2}\right)=\operatorname{sqrt}(13)=3.6$. - $|a b|+|b c|>|a c| \Rightarrow 5+2.82>3.6$ - $|b c|+|a c|>|a b| \Rightarrow 2.82+3.6>5$ - $|a b|+|a c|>|b c|=5+3.6>2.82$ Second, the point $p(5,4)$ belong to the triangle abc and the point $q(7$, 4) does not as show in the graphic above. So, the answer is 1. Function Description Complete the function pointsBelong in the editor below.


Second, the point $p(5,4)$ belong to the triangle abc and the point $q(7$, 4) does not as show in the graphic above. So, the answer is 1. Function Description Complete the function pointsBelong in the editor below. pointsBelong has the following parameter(s): int $x_{1}, y 1, x_{2}, y_{2}, x_{3}, y_{3}$ : integer coordinates of the three points that may create a valid triangle int $x p, y p, x q, y q$ : integer coordinates of the two points $p$ and $q$ Returns: int: an integer value that represents the scenario Constraints - $0 \leq x 1, y 1, x 2, y 2, x 3, y 3, x p, y p, x q, y q \leq 2000$ Input Format for Custom Testing Sample Case 0 Sample Input 0 \[ \begin{array}{ll} \text { STDIN } & \text { Function } \\ ---- & ----- \\ 0 \rightarrow & (\mathrm{x} 1, \mathrm{y} 1)=(0,0) \end{array} \]

Use Python

The function is expected to return an INTEGER.

# The function accepts following parameters:

# 1. INTEGER x1

# 2. INTEGER y1

# 3. INTEGER x2

# 4. INTEGER y2

# 5. INTEGER x3

# 6. INTEGER y3

# 7. INTEGER xp

# 8. INTEGER yp

# 9. INTEGER xq

# 10. INTEGER yq

#

def pointsBelong(x1, y1, x2, y2, x3, y3, xp, yp, xq, yq):

Public Answer

CW8ZFV The First Answerer