Ask Your Question

Calculating points distance (application freezes)

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

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;    



    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);




    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);



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

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

Guanta gravatar image

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

edit flag offensive delete link more


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 -0500 )edit
Login/Signup to Answer

Question Tools


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

Seen: 416 times

Last updated: Apr 01 '13