/*! Get the extremities of the line. \param ip1 : Coordinates of the first extremity. \param ip2 : Coordinates of the second extremity. */ void vpMeLine::getExtremities(vpImagePoint &ip1, vpImagePoint &ip2) { /*Return the coordinates of the extremities of the line*/ ip1.set_i( PExt[0].ifloat ); ip1.set_j( PExt[0].jfloat ); ip2.set_i( PExt[1].ifloat ); ip2.set_j( PExt[1].jfloat ); }
/*! Computes the intersection point of two lines. The result is given in the (i,j) frame. \param line1 : The first line. \param line2 : The second line. \param ip : The coordinates of the intersection point. \return Returns a boolean value which depends on the computation success. True means that the computation ends successfully. */ bool vpMeLine::intersection(const vpMeLine &line1, const vpMeLine &line2, vpImagePoint &ip) { double a1 = line1.a; double b1 = line1.b; double c1 = line1.c; double a2 = line2.a; double b2 = line2.b; double c2 = line2.c; try{ double i=0, j=0; double denom = 0; if (a1 > 0.1) { denom = (-(a2/a1) * b1 + b2); //if (denom == 0) if (std::fabs(denom) <= std::numeric_limits<double>::epsilon()) { std::cout << "!!!!!!!!!!!!! Problem : Lines are parallel !!!!!!!!!!!!!" << std::endl; return (false); } //if (denom != 0 ) if (std::fabs(denom) > std::numeric_limits<double>::epsilon()) { j = ( (a2/a1)*c1 - c2 ) / denom; i = (-b1*j - c1) / a1; } } else { denom = (-(b2/b1) * a1 + a2); //if (denom == 0) if (std::fabs(denom) <= std::numeric_limits<double>::epsilon()) { std::cout << "!!!!!!!!!!!!! Problem : Lines are parallel !!!!!!!!!!!!!" << std::endl; return (false); } //if (denom != 0 ) if (std::fabs(denom) > std::numeric_limits<double>::epsilon()) { i = ( (b2/b1)*c1 - c2 ) / denom; j = (-a1*i - c1) / b1; } } ip.set_i( i ); ip.set_j( j ); return (true); } catch(...) { return (false); } }