判断一个点是否在在三角形和矩形
程序员文章站
2022-07-04 09:09:58
...
bool sanjiaoxing()
{
auto x1 = pair<int, int>(1, 0);
auto x2 = pair<int, int>(5, 0);
auto x3 = pair<int, int>(3, 3);
auto test = pair<int, int>(30, 2);
int bijiao = (x2.first - x1.first)*(x3.second - x1.second) -
(x2.second - x1.second)*(x3.first - x1.first);
int b_1_2= (x2.first - x1.first)*(test.second - x1.second) -
(x2.second - x1.second)*(test.first - x1.first);
int b_3_1 = (x1.first - x3.first)*(test.second - x3.second) -
(x1.second - x3.second)*(test.first - x3.first);
int b_2_3 = (x3.first - x2.first)*(test.second - x2.second) -
(x3.second - x2.second)*(test.first - x2.first);
cout << "bijiao:"<<bijiao << endl;
cout << "b1:" << b_1_2 << endl;
cout << "b2:" << b_3_1 << endl;
cout << "b3:" << b_2_3 << endl;
return 1;
}
矩形待补充
上一篇: CSS-边距2-实现一个三角形
下一篇: css3烟花效果