Ask Your Question
0

Calculating points distance (application freezes)

asked 2013-04-01 17:30:41 -0600

Tomazi gravatar image

Hello people...!

Got a rather odd question but it is really stooping my development.

I am calculating a distance between two points for two separate center points of a bounding box. My application works fine after I put the code to calculate the distance between points of the first center.

When I add the code to my application to calculate the distance between points of the second center point my application freezes completely.

There are no compiler errors neither run time errors the application just stops (freezes) after a second or 2 and stays like this forever.....

vector<Point> Rightarm;
    vector<Point> Leftarm;

    vector<Point> Left_Arm_xy;
    vector<Point> Right_Arm_xy;

    vector<double> Left_Point_distance;
    vector<double> Right_Point_distance;    

Left_Arm_xy.push_back(cv::Point(center.x,center.y));

    Right_Arm_xy.push_back(cv::Point(center1.x,center1.y));


    double Pt1; 
    double Pt2; 
    for(vector<Point>::iterator iter_a = Left_Arm_xy.begin()+1; iter_a != Left_Arm_xy.end(); ++iter_a)
    {

        Pt1 = pow((double) iter_a->x - (iter_a -1)->x,2);
        Pt2 = pow((double) iter_a->y - (iter_a -1)->y,2);

            double result_a;
            result_a  = (Pt1 + Pt2);

            Left_Point_distance.push_back(sqrt(result_a));

    }



    //----------------------------------------------------------------------------->

    double Pt3; 
    double Pt4; 
    for(vector<Point>::iterator iter_b = Right_Arm_xy.begin()+1; iter_b != Right_Arm_xy.end(); iter_b)
    {

        Pt3 = pow((double) iter_b->x - (iter_b -1)->x,2);
        Pt4 = pow((double) iter_b->y - (iter_b -1)->y,2);

            double result_b;
            result_b  = (Pt3 + Pt4);

            Right_Point_distance.push_back(sqrt(result_b));

    }

Really have no idea of why this could be happening....could anyone possibly suggest an issue that exists withing the code....? Regards

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-04-01 17:45:43 -0600

Guanta gravatar image
++iter_b

-> Second for-loop runs forever if you don't update your iterator

edit flag offensive delete link more

Comments

HEHE thank you so much Not to sure how i didn't spot this but but once again THANKS. regards

Tomazi gravatar imageTomazi ( 2013-04-01 17:50:29 -0600 )edit

Question Tools

Stats

Asked: 2013-04-01 17:30:41 -0600

Seen: 533 times

Last updated: Apr 01 '13