Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given n > 3 points P1 = (x1, y1), ..., Pn = (xn, yn) in the Cartesian plane, dev

ID: 3852150 • Letter: G

Question

Given n > 3 points P1 = (x1, y1), ..., Pn = (xn, yn) in the Cartesian plane, develop an algorithm to check whether all points are in a triangle with the vertices of the triangle being three points from P1 = (x1, y1), ..., Pn = (xn, yn).

NOTE: For the algorithm's, not looking for full programs. Looking more along the lines of half pseudocode, half coding. See example below of bubblesort.

ALGORITHM BubbleSort(A[0.n 1]) //Sorts a given array by bubble sort //Input: An array A[0.. 1 of orderable elements //Output: Array A[0..n - 1] sorted in ascending order for i 0ton_2do for j 0 to n-2-do

Explanation / Answer

The algorithm for checking whether all the points are in a triangle within the vertices of the triangle is given below.Hope it helps..

Let the three corners be (a1, b1), (a2, b2) and (a3, b3) & co-ordinates of the given point X be (a, b)

1) Calculate the area of triangle,

i.e. Area A = [ a1(b2 – b3) + a2(b3 – b1) + a3(b1-b2)]/2

2) Area of the triangle XAB.Use same formula as above & let the area be A1.
3) Area of the triangle XBC. Let this area be A2.
4) Area of the triangle XAC. Let this area be A3.
5) If 'X' lies inside the triangle, then A1 + A2 + A3 must be equal to A.

Please rate the answer if it helped......Thankyou

Hope it helps.....

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote