I need a mathematical explanation and javascript solution to the below question A triangle formed by the three points a(
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
I need a mathematical explanation and javascript solution to the below question A triangle formed by the three points a(
I need a mathematical explanation and javascript solution to thebelow questionA triangle formed by the three points a(x1, y1), b(x2, y2) andc(x3, y3) is a non-degenerate triangle if the following rules arerespected (/ab/ is the length of the line between points a and b);. . Tabſ + |bc| > |ac| |bc| + |ac| > |ab| . |ab| + |ac| >|bc| A point belongs to a triangle if it lies somewhere on orinside the triangle. Given two points p = (xp, yp) and q = (xq,yq), return the correct scenario number: • O. If the triangle abcdoes not form a valid non-degenerati triangle. • 1: If point pbelongs to the triangle but point q does not. • 2. If point qbelongs to the triangle but point p does not. • 3. If both points pand q belong to the triangle. • 4: If neither point p nor point qbelong to the triangle. Example 1 = a(x1, yl): (2, 2) 2= b(x2,y2):(7,2) 3 = c(x3,y3): (5,4) p = p(xp, yp): (4,3) 9 = 9(x9, ya): (7,4)02 6 5 4 35.4) 97.4) 3 p 4,3) 2 1 (22) 2K7.2) 1 Х 1 2 3 4 5 6 7 .First, the triangle abc forms a valid non-degenerate triangle |ab|= 7 -2 = 5. [bc] = sqrt(7-57 +(4-2) = sqrt(22 + 22) = sqrt(8) =2.82. |ac= sqrt(15 - 27 +(4 - 2) = (32+ 22) = sqrt(13) =3.6. • Jab]+ [bc] > Jac! => 5+2.82 > 3.6 • 1bc| + |ac| > ab=>2.82 +3.6>5 . |ab| + |ac|> [bc=> 5+ 3.6 > 2.82 Second,the point p(5, 4) belong to the triangle abc and the point (7,4)does not as show in the graphic above. So, the answer is 1.Function Description Complete the function pointsBelong in theeditor below. pointsBelong has the following parameter(s): int x1,y1, x2, y2, x3, y3: integer coordinates of the three points thatmay create a valid triangle int xp, yp, xq, yq: integer coordinatesof the two points p and a Returns: int: an integer value thatrepresents the scenario Constraints • O $x1y1. x2, 92. x3. y3, xp.yp, xq, yg = 2000 TO STDIN Function 0 (x1, y) = (0,0) 0 2 → (x2,y2)= (2,0) 2 0 4 4 ने (x3,3) (4,0) 0 2 p = (xp, yp) = (2,0) 0 9 = =(xq,yq) =(4,0) 0 Sample Output 0 Explanation o תס 5 4 3 2 1 1 (0,0)22,0) 3/4.0) X- 1 1 2 3 P (2.0) 4 5 9 (4,0) First, the lines do notform a valid non-degenerate triangle: The three points a, b, c lieon the same line, so it is impossible to form a triangle. Theanswer is 0. Language Python 3 V Autocomplete Ready # # 1>#!/bin/python3 ... 10 11 12 # Complete the pointsBelong'function below. 13 # 14 # The function is expected to return anINTEGER. 15 # The function accepts following parameters: 16 1.INTEGER X1 17 2. INTEGER yi 3. INTEGER X2 I 19 4. INTEGER 72 20 5.INTEGER X3 21 6. INTEGER 3 22 7. INTEGER XP 23 8. INTEGER YP 24 9.INTEGER X9 10. INTEGER yg 18 # I 11 E 11 # # 25 26 27 28 29 36 D00def pointsBelong(x1, yi, x2, 72, x3, 93, P. yp, xq, ya) # Writeyour code bere 31 > it name - main