Home > Back-end >  7-9 triangle judgment (15 points)
7-9 triangle judgment (15 points)

Time:10-21

A given plane coordinates of any three points (x1, y1), (x2, y2), (x3, y3? ), check whether they constitute a triangle,

Input format:
Input sequence is given in a line of six? [100100] within the scope of digital, namely three point coordinates x1, y1? , x2? , y2? , the x3? , y3? ,

The output format:
If the three points can't form a triangle, the output in one line "Impossible". If you can, then output in one line of the triangle pupil, format is "L=c, A=area", the output to 2 decimal places,

Input the sample 1:
4 5 6 7 8 9
The output sample 1:
L=10.13, 3.00
A=Enter the sample 2:
4, 6, 8 12 12 18
The output sample 2:
Impossible
Thinking: area was calculated by the vector of cross-product
Code:
#include
#include

Int main (int arg c, const char * argv [])
{
Double x1, x2, x3, y1, y2, y3.
Double l, a;
The scanf (" % lf lf lf lf lf % % % % % lf ", & amp; X1, & amp; Y1, & amp; X2, & amp; Y2, & amp; The x3, & amp; Y3);
If ((x1 - x2) * (y2, y3)==(x2, x3) * (y1, y2))
{
Printf (" Impossible ");
}
The else
{
(l=SQRT (pow (x1, x2), 2) + pow ((y1, y2), 2)) + SQRT (pow ((x1 - x3), 2) + pow ((y1, y3), 2)) + SQRT (pow ((x2, x3), 2) + pow ((y2 - y3), 2));
A=fabs ((x1, x2) * (y3 - y2) - (x3 - x2) * (y1, y2))/2;
Printf (" lf L=%. 2, A=%. 2 lf ", L, A);
}
return 0;
}
The code has been can't pass the final test, the sample is correct, don't know what a great god can help me

CodePudding user response:

If ((x1 - x2) * (y2, y3)==(x2, x3) * (y1, y2)) so is wrong, such as
Floating point Numbers to use such as
Fabs (their) & lt; 1 e - 12;

CodePudding user response:

Logic seems no problem
Printf end to add \ n?

CodePudding user response:

At 3 o 'clock not collinear can form a triangle, there is no need to calculate the distance

CodePudding user response:

Long knowledge, but after I get rid of or can't, I with Helen before the formula to calculate area, can be through, so I don't think this judgment equal place should be the key problem

CodePudding user response:

Fabs is o (y2 - y1/x2 - x1) and fabs (y3 - y1/x3 - x1) are equal

CodePudding user response:

Reply how to separate a layer of ah,,,

CodePudding user response:

refer to fifth floor truth is right or wrong response:
fabs is o (y2 - y1/x2 - x1) and fabs (y3 - y1/x3 - x1) is equal to

This place I will know that hasn't been noticed before, but now I don't understand is area place why not

CodePudding user response:

Fun
reference 1 floor response:
if ((x1, x2) * (y2, y3)==(x2, x3) * (y1, y2)) so is wrong, such as
Floating point Numbers to use such as
Fabs (their) & lt; 1 e - 12;

Long knowledge, but after I get rid of or can't, I with Helen before the formula to calculate area, can be through, so I don't think this judgment equal place should be the key problem

CodePudding user response:


Calculate area also involves floating-point arithmetic, inaccurate,
It is best to calculate the vector between the three points,
Above my reply is a little problem, trigonometric function lost earlier, computing
(y2 - y1)/(x2 - x1) and (y3 - y1)/(x3 - x1) are equal, two points into the minimalist style, through the reduction of a fraction, determine whether the denominator is equal and molecules are equal, equal cannot form a triangle, can,

CodePudding user response:

references 9/f, the truth is right or wrong response:
calculate area also involves floating-point arithmetic, inaccurate,
It is best to calculate the vector between the three points,
Above my reply is a little problem, trigonometric function lost earlier, computing
(y2 - y1)/(x2 - x1) and (y3 - y1)/(x3 - x1) are equal, two points into the minimalist style, through the reduction of a fraction, determine whether the denominator is equal and molecules are equal, equal cannot form a triangle, can,

I was thinking, I am the division into multiplication, prevent it from the denominator is zero, one thousand concrete at the time of floating-point arithmetic which local precision will be inaccurate, still hope bosses give advice or comments

CodePudding user response:

Score comparison, it is after after reduction to common denomiator or reduction, than molecules, the denominator score mother, as long as the point coordinates are expressed in plastic, need not consider floating point,

CodePudding user response:


refer to fifth floor truth is right or wrong response:
fabs is o (y2 - y1/x2 - x1) and fabs (y3 - y1/x3 - x1) is equal to


Not fabs, the wrong drops
Is fabs ((x1, x2) * (y2, y3) - (x2, x3) * (y1, y2)) & lt; 1 e - 12
Not many fabs

Write this, have to complain about the building Lord, you will not be able to get two intermediate variable dx1=x2 - x1, dy1=y2 - y1, dx2=x3 - x1, dy2=y3 - y1
This is trouble over and over again not to say, to restore to knock again and again repeat

Dy1/dx1 and dy2/dx2 quite so slope
Slope must be the same is true, dy1/dx1 and dy1/dx1 not on a straight line (slope and k - k is about the relation of coordinate axisymmetric)

Can only be fabs (dy2 - dx2 dx1 * * dy1) & lt; 1 e - 12 so judgment

CodePudding user response:

The building only the last question wrong, wrong is not on the formula itself, if formula is wrong, that is not a problem the problem of the
Should or boundary conditions are more likely to
  • Related