Ask Your Question
0

Convert two points to rho and theta

asked 2013-04-18 09:44:32 -0600

Bazze gravatar image

Hello!

I need to convert two points, (x1,y1) and (x2,y2), to rho and theta. What is the simplest way to do that?

This is my try so far and I'm not sure if it's correct:

cv::Vec2f LineProcessor::pointsToRhoTheta(double x1,double x2,double y1,double y2){

   double cvTheta=0;
   double cvRho=0;
   double k=0;
   if (x2-x1!=0) {
      k=(y2-y1)/(x2-x1);
   } else {
      k=99999;
   }

   double xSlope,ySlope,m;
   m=y1-k*x1;

   xSlope=-m/(k+(1/k));
   ySlope=m/(pow(k,2)+1);

   if (std::atan2((ySlope),(xSlope))<0) {
      cvTheta=std::atan2((ySlope),(xSlope))+CV_PI;
      cvRho=-std::sqrt(pow(xSlope,2)+pow(ySlope,2));
   } else {
      cvTheta=std::atan2((ySlope),(xSlope));
      cvRho=std::sqrt(pow(xSlope,2)+pow(ySlope,2));
   }

   cv::Vec2f lineRhoTheta;

   lineRhoTheta[0]=cvRho;
   lineRhoTheta[1]=cvTheta;

   return lineRhoTheta;
}

Has anyone done this before?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-04-18 14:15:21 -0600

Guanta gravatar image
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-18 09:44:32 -0600

Seen: 1,147 times

Last updated: Apr 18 '13