2. Do They Belong? A triangle formed by the three points a(x1, y1), b(x2, y2) and c(x3, y3) is a non- degenerate triangle if the following rules are respected (/ab/ is the length of the line between points a and b): • Tabl + bcl > |ac| |bc| + |ac| > |ab| labſ + lacl > |bc| A point belongs to a triangle if it lies somewhere on or inside the triangle. Given two points p = (xp, yp) and q = (xq, yq), return the correct scenario number: • O. If the triangle abc does not form a valid non-degenerate triangle. 1: If point p belongs to the triangle but point qdoes 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. Data Structure 2. Do They Belong? A triangle formed by the three points a(x1, y1), b(x2, y2) and c(x3, y3) is a non-degenerate triangle if the following rules are respected (/ab/ is the length of the line between points a and b) e e |ab+ |bc| > |ac| |bc| + |ac| > |abl |ab| + |ac| > | bc e A point belongs to a triangle if it lies somewhere on or inside the triangle. Given two points p = (xp, yp) and q = (xq, yq), return the correct scenario number: e . O. 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 6 5 3 (5,4) 1 = a (x1, y1): (2, 2) 2 = 6(x2,y2): (7,2) 3 = c(x3,y3): (5,4) P = p(xp, yp): (4,3) 4 9 (7,4) 3 P (4,3) Example 6 5 3 (5.4) 4 1 = a (x1, yl): (2, 2) 2 = b(x2,y2): (7,2) 3 = c(x3, y3): (5,4) p = p(xp, yp): (4,3) a = 9(xq, ya): (7,4) 9 (74) 3 P (4.3) N 1 (2,2) 2 (7.2) 1 X 1 2 3 4 5 6 7 8 у First, the triangle abc forms a valid non-degenerate triangle . • Jabl = 7 - 2 = 5. bc) = sqrt((7-5)2 + (4-2)2) = sqrt(22 + 22) = sqrt(8) = 2.82. |ac| = sqrt((5 - 2)2 (4-2)) = (32 + 2) = sqrt(13)=3.6. • Jabl + bc) > Jacl => 5 + 2.82 > 3.6 . |bc| + |ac| > |abl => 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 q(7,4) does not as show the graphic above. So, the answer is 1. . Function Description MAK 2 Function Description Complete the function pointsBelong in the editor below. pointsBelong has the following parameter(s): int x1, y1, X2, y2, X3, y3: integer coordinates of the three points that may create a valid triangle int xp, yp, xq, yq: integer coordinates of the two points p and q Returns: int: an integer value that represents the scenario Constraints . 0



Answer :

Other Questions