//
// main.cpp
// 12
//
// Created by WeiWei on 9/27/15.
// Copyright © 2015 ZhuWei. All rights reserved.
//
#include
#include
using namespace std;
struct Vector2{
float x;
float y;
};
Vector2 p1;
Vector2 p2;
Vector2 p3;
int main()
{
float x,y;
cout<<"Enter the Position of p1\n";
cin>>x >> y;
p1.x = x;
p1.y = y;
cout<<"( "<< x <<" , " << y << ") \n";
cout<<"Enter the Position of p2\n";
cin>>x >> y;
p2.x = x;
p2.y = y;
cout<<"( "<< x <<" , " << y << ") \n";
cout<<"Enter the Position of p2\n";
cin>>x >> y;
p3.x = x;
p3.y = y;
cout<<"( "<< x <<" , " << y << ") \n";
float edge1= sqrt( (p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y) );
float edge2= sqrt( (p3.x-p2.x)*(p3.x-p2.x) + (p3.y-p2.y)*(p3.y-p2.y) );
float edge3= sqrt( (p1.x-p3.x)*(p1.x-p3.x) + (p1.y-p3.y)*(p1.y-p3.y) );
float p= (edge1 + edge2 + edge3)/2;
float s = sqrt(p*(p-edge1)*(p-edge2)*(p-edge3));
if(s==0)
{
float max = 0.0;
if(edge1 >=edge2 && edge1 >=edge3)
max = edge1;
if(edge2 >=edge1 && edge2 >=edge3)
max = edge2;
if(edge3 >=edge2 && edge3 >=edge1)
max = edge3;
cout<< " the three points are aligned in a straight line" <<"the length of the line is : "<< max <
}
else
cout<< "the S is : " << s <
return 0;
}
这是第一题的答案。 第二题 有点麻烦, 似乎要算三角形的外接圆 然后求出外接圆 圆心。 我高中毕业好多年了, 这些鸟东西都忘了 😄。 我现在只是个游戏程序员 用不了这些鬼东西。 俺不会