How can u say that a given point is in a triangle?
1. with the co-ordinates of the 3 vertices specified.
2. with only the co-ordinates of the top vertex given.



How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices speci..

Answer / vadivel

solution for 1st case:
Given:(x1,y1),(x2,y2),(x3,y3),the co-ordinates of the
vertices of the triangle.
Let (xx,yy) be the pt to be located.
Find the equations of the lines {(x1,y1),(x2,y2)} and
{(x1,y1)(x3,y3)} using the formula
((y-y1)/(y2-y1))=((x-x1)/(x2-x1))

Now substitute the y value in the 2 equations got. You 'll
be getting the x limits. If the given x value lies within
the limits you have found,the given pt is within the
triangle or else it is not.

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More C Code Interview Questions

In a gymnastic competition, scoring is based on the average of all scores given by the judges excluding the maximum and minimum scores. Let the user input the number of judges, after that, input the scores from the judges. Output the average score. Note: In case, more than two judges give the same score and it happens that score is the maximum or minimum then just eliminate two scores. For example, if the number of judges is 5 and all of them give 10 points each. Then the maximum and minimum score is 10. So the computation would be 10+10+10, this time. The output should be 10 because 30/3 is 10.

0 Answers   TCS,


main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

1 Answers  


main() { printf("\nab"); printf("\bsi"); printf("\rha"); }

3 Answers  


void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above

2 Answers   HCL,


Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.

3 Answers   Wipro,






how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

0 Answers  


What is the subtle error in the following code segment? void fun(int n, int arr[]) { int *p=0; int i=0; while(i++<n) p = &arr[i]; *p = 0; }

1 Answers  


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }

3 Answers   Hexaware,


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }

1 Answers  


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

0 Answers  


main() { extern int i; i=20; printf("%d",i); }

1 Answers   Value Labs,


Categories