C++ 在阵列中的两点之间进行检查

C++ 在阵列中的两点之间进行检查,c++,C++,我有一个数组,里面填充了I元素。我想检查一下他们两人之间发生了什么事。到目前为止,我只能检查这个数组中的一个特定元素发生了什么,我如何在2之间进行检查 我的数组是这样填写的: int iSegment = pDatagram->header.start - 1; pdX[0] = (-(pDatagram->distances[0]) * ROD4::dCos_table[0]); pdY[0] = ( (pDatagram->distances[0]) * ROD4::dS

我有一个数组,里面填充了I元素。我想检查一下他们两人之间发生了什么事。到目前为止,我只能检查这个数组中的一个特定元素发生了什么,我如何在2之间进行检查

我的数组是这样填写的:

int iSegment = pDatagram->header.start - 1;

pdX[0] = (-(pDatagram->distances[0]) * ROD4::dCos_table[0]);
pdY[0] = ( (pDatagram->distances[0]) * ROD4::dSin_table[0]);
iSegment += 1;  //correct start of interval #1

//calculate cartesian values
for(int i = 1 ; i < pDatagram->distanceCount; i++)
{
   pdX[i] = (-(pDatagram->distances[i]) * ROD4::dCos_table[iSegment]);
   pdY[i] = ( (pDatagram->distances[i]) * ROD4::dSin_table[iSegment]);
   iSegment += pDatagram->header.resolution;
}
int-iSegment=pDatagram->header.start-1;
pdX[0]=((pDatagram->distance[0])*ROD4::dCos_表[0]);
pdY[0]=((pDatagram->距离[0])*ROD4::dSin_表[0]);
iSegment+=1//间隔#1的正确开始
//计算笛卡尔值
对于(inti=1;idistanceCount;i++)
{
pdX[i]=((pDatagram->distance[i])*ROD4::dCos_表[iSegment]);
pdY[i]=((pDatagram->distance[i])*ROD4::dSin_table[iSegment]);
iSegment+=pDatagram->header.resolution;
}
我用以下几行检查第70元素中发生了什么:

pdX[70] = (-(pDatagram->distances[70]) * ROD4::dCos_table[70]);
if( pdX[70] > 0 && pdX[70] < 45 ) // these are to test the distances of the 70th element
{
    cout << "My line is broken in the X axis" << endl;
}
pdX[70]=((pDatagram->distance[70])*ROD4::dCos_表[70]);
如果(pdX[70]>0&&pdX[70]<45)//这些是为了测试第70个元素的距离
{

可以尝试以下方法,但要根据您的需要进行调整

for(int i = 1; i < pDatagram->distanceCount; i++) {

    pdX[i] = (-(pDatagram->distances[i]) * ROD4::dCos_table[iSegment]);
    pdY[i] = ( (pDatagram->distances[i]) * ROD4::dSin_table[iSegment]);
    iSegment += pDatagram->header.resolution;

    if (i <= 70 && i >= 40) {
        if( pdX[i] > 0 && pdX[i] < 45 ) {
            cout << "My line is broken in the X axis" << endl;
        }
    }
}
for(int i=1;idistanceCount;i++){
pdX[i]=((pDatagram->distance[i])*ROD4::dCos_表[iSegment]);
pdY[i]=((pDatagram->distance[i])*ROD4::dSin_table[iSegment]);
iSegment+=pDatagram->header.resolution;
如果(i=40){
如果(pdX[i]>0&&pdX[i]<45){

cout如果您使用的是C样式的数组,我只会使用while循环从头到尾遍历所需的元素。尽管我仍然不确定pdX是什么,但它似乎是关于sin/cos的坐标(而不是直角笛卡尔形式)因为你的条件要求0和45,所以我假设你说的是角度,虽然我可能错了。请澄清,这样我可以编辑这个答案

size_t x_start = 40;
size_t x_end = 70;

size_t counter = x_start;
bool line_broken_x = false;

while (line_broken_x != false && counter != x_end+1)
{
    if( pdX[counter] < 0 || pdX[counter] > 45 )
        line_broken_x = false;

    counter++;
}

if (line_broken_x == true)
    cout << "My line is broken in the X axis" << endl;
else
    cout << "My line is not broken in the X axis" << endl;
size\t x\u start=40;
尺寸x端=70;
大小\u t计数器=x\u开始;
bool line_breaked_x=false;
while(line_breaked_x!=false&&counter!=x_end+1)
{
如果(pdX[计数器]<0 | | pdX[计数器]>45)
线_断开_x=假;
计数器++;
}
如果(行_断开_x==真)

cout
std::for_each
maybe?虽然我能了解你所做的,但我不明白最后一个问题。你所说的“发生了什么”是什么意思。你在检查所有这些点之间的“线是否断了”吗?@woosah是的,伙计。看到我对第70个元素做了什么吗?我想对第40和第70个元素之间的每一个元素都这样做(例如)你使用的是C++容器,用于PDX/PDY还是普通C数组?如果使用STD C++容器,你使用C++ 11吗?