テキスト ファイルに 10000 行と 10 列のデータ セットがあります。ここにいくつかのサンプルがあります-
# x1 y1 x2 y2 x3 y3 x4 y4 Area
1 0.0000 0.0000 0.8147 0.0000 0.8147 0.1355 0.0000 0.1355 0.1104
2 0.8147 0.0000 1.0000 0.0000 1.0000 0.1355 0.8147 0.1355 0.0251
3 0.8147 0.1355 0.9058 0.1355 0.9058 0.8350 0.8147 0.8350 0.0637
4 0.0000 0.1355 0.8147 0.1355 0.8147 1.0000 0.0000 1.0000 0.7043
5 0.9058 0.1355 1.0000 0.1355 1.0000 0.8350 0.9058 0.8350 0.0659
6 0.9058 0.8350 1.0000 0.8350 1.0000 1.0000 0.9058 1.0000 0.0155
7 0.8147 0.8350 0.9058 0.8350 0.9058 1.0000 0.8147 1.0000 0.0150
このプログラムを使ってこれらの点を確認したい-
#include <iostream>
#include <cmath>
using namespace std;
double CheckPoint(){
double slope, intercept,A, B, C, D,px, py,left, top, right, bottom,dx, dy;
cin >> A; // take from column
cin >> B; // take from column
cin >> C; // take from column
cin >> D; // take from column
cin >> px; // take value from other rows and column and check
cin >> py; // take value from other rows and column and check
dx = C - A;
dy = D - B;
slope = dy / dx;
// y = mx + c
// intercept c = y - mx
intercept = B - slope * A; // which is same as D - slope * C
// For Bounding Box
if(A < C)
{
left = A;
right = C;
}
else
{
left = C;
right = A;
}
if(B < D)
{
top = B;
bottom = D;
}
else
{
top = B;
bottom = D;
}
if( slope * px + intercept > (py - 0.01) &&
slope * px + intercept < (py + 0.01))
{
if( px >= left && px <= right &&
py >= top && py <= bottom )
{
// cout the numbers of common point and the line number
}
else
// cout the numbers of common point and the line number
}
else
// cout no common point;
}
int main()
{
cout<<CheckPoint();
return 0;
}
まずしたいのは
- x1 から A の値を取る
- y1 から B の値を取る
- x2 から C の値を取る
- y2 から D の値を取る
- x3、y3、x4、y4 との共通点があるかどうかを確認します。ただし、それ自体の行の値はチェックしません。このプロセスは、他の行についても続行されます。
それから私はしたいです
- x2 から A の値を取る
- y2 から B の値を取る
- x3 から C の値を取る
- y3 から D の値を取る
- x1、y1、x4、y4 との共通点があるかどうかを確認します。上記のように、それ自体の行の値をチェックせず、row2、row3 ....などにも適用されます。
コメントへの返信例
プログラムが A=0.0000 B=0.0000 C=0.8147 D=0.0000 を取得する場合、値を x3=0.8147 y3=0.1355 x4=0.0000 y4=0.1355 と比較しません。つまり、値を取得する行をスキップします。 x1、y1、x2、y2。
2 行目から A、B、C、D の値を取得する場合、つまり 0.A=8147 B=0.0000 C=1.0000 D=0.0000 の場合、2 行目の x3、y3、x4、y4 の値をスキップします。 .
一致するポイントの数をカウントし、ポイントが見つかった行の数を返すようにしたかったのです。どうすればいいですか?