[問題] 判斷錯誤??
我想計算兩個座標 x1 y1 和 x2 y2 的距離是否大於半徑
是的話印出加入成功 否的話印出加入失敗
在這邊設的半徑為 3
根據距離函式算出來的也是3 不知道為啥怎麼改都還是加入失敗
改成小於等於半徑印出加入成功 大於印出加入失敗也都是一樣
想請問一下哪邊出問題了嗎
非常感謝 <(_ _)>
#include <cstdlib>
#include <iostream>
#include <math.h>
#define radius 3
using namespace std;
bool check_its_point(double , double , double , double );
double distance(double , double , double , double );
int main(int argc, char *argv[])
{
// 8.24499, -0.98998 要輸入的數值 與 6, 1比較
// 5.75501, 3.98998 要輸入的數值 與 6, 1比較
// 7.47141, -1.61438 要輸入的數值 與 6, 1比較
if( check_its_point(5.75501, 3.98998 ,6 ,1 ) == true)
{
cout << "加入成功" << endl;
}
else
{
cout << "加入失敗" << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
bool check_its_point(double x1, double y1, double x2, double y2)
{
double r = radius;
cout << distance(x1, y1, x2, y2 ) << endl;
if( distance(x1, y1, x2, y2 ) > r )
{
cout << x1 << "," << y1 << "到" << x1 << "," << y2 << "距離大於" << r <<" 不存入" << endl;
//cout << x1 << "," << y1 << "到" << x2 << "," << y2 << "距離小於" << r <<" 存入" << endl;
return false;
}
return true;
}
double distance(double x1, double y1, double x2, double y2)
{
double distance = 0;
distance = sqrt( pow((x2 - x1), 2) + pow((y2 - y1), 2));
cout << "距離 = " << distance << endl;
return distance;
}
--
柏油->Two-Face ◢~
你想作什麼? ◢█ ██~ ● 正面就炸你
放開那女孩! ◢ ≡ ◥◣ \ 反面炸你家
▔▔▔▔▔▔▔▔▔ ◣ ▔▔ -◎-⊙- / ◤
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ -皿 ╭▌ 有時正氣凜然
20080722 pm 18:20左右 ψQSWEET ◣ ︶ ◤ 目 有時卻兇猛霸道
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.128.207
推
02/20 00:47, , 1F
02/20 00:47, 1F
推
02/20 01:00, , 2F
02/20 01:00, 2F
→
02/20 01:01, , 3F
02/20 01:01, 3F
推
02/20 01:06, , 4F
02/20 01:06, 4F
→
02/20 01:07, , 5F
02/20 01:07, 5F
→
02/20 01:13, , 6F
02/20 01:13, 6F
→
02/20 01:15, , 7F
02/20 01:15, 7F
→
02/20 01:16, , 8F
02/20 01:16, 8F
→
02/20 11:43, , 9F
02/20 11:43, 9F
→
02/20 11:43, , 10F
02/20 11:43, 10F
※ 編輯: lalawolala 來自: 210.240.186.16 (02/20 12:13)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章