Answer the question
In order to leave comments, you need to log in
A problem in C about points on a coordinate area?
Given real numbers a, b, c, d, e, f, gh It is known that the points (a, b) and (c, d) do not lie on the line passing through the points (e, f) and (gh). The line I divides the coordinate plane into two half-planes. Find out whether the points (a, b) and (C, d) belong to the same half-plane. To solve this problem, you need to know that the equation is a straight line passing through two different points (e, f) and (gh). has the form:
(xe)*(hf)-(yf)*(ge)=0
Use only standard libraries, only C without C++
If there are enthusiasts ready to solve the problem, write in the answers I will be very
grateful telegram vitalianskiy_79
Answer the question
In order to leave comments, you need to log in
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
float a,b,c,d,e,f,g,h,f1,f2;
printf("a,b,c,d,e,f,g,h,\n");
scanf("%f%f%f%f%f%f%f%f", &a,&b, &c, &d, &e, &f, &g, &h);
f1=(a-e)*(h-f)-(b-f)*(g-e);
scanf ("(a-e)*(h-f)-(b-f)*(g-e)=%f", f1 );
f2=(c-e)*(h-f)-(d-f)*(g-e);
scanf("(c-e)*(h-f)-(d-f)*(g-e)=%f", f2 );
if ((f1>0) && (f2>0))
{printf("Yes");}
else if ((f1<0) && (f2<0))
{printf("Yes");}
else
{printf("NO");}
return 0;
}
Substitute the coordinates of the points into the left side of the straight line equation. If the values of the same sign are obtained, then the points are in the same half-plane, if different, then in different ones.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question