# Convert two points to rho and theta

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?