Hi all!
Starting from 2d lines as vec3(a,b,c) with ax+by+c=0 in cartesian coordinates and (a,b) normalized , i need to compute the rho theta representation of Hough transform vec2(rho, theta) in polar representation theta in [0,PI/2].
I also need the reverse operation.
To begin i write few function to test this in shader toy :
vec4 DrawCartesian(in vec2 uv, in vec3 dr)//in put uv and line
{
if(abs(dot(uv,dr.xy)+dr.z)<0.005) return vec4(1.,0,0.,1.);
return vec4(0.0);
}
vec4 DrawPolarline(vec2 uv, float r, float t)
{
vec2 er = vec2(cos(t),sin(t));
float ui= dot(uv.xy,er)-r;
if(abs(ui)<0.005) return vec4(0,0.0,1.0,0.0);
return vec4(0.0);
}
and 2 functions to try the conversion :
float linePtDist(vec2 pt,vec3 dr) //to compute rho
{
vec2 p = vec2(0,dr.z);
float t = dot(dr.xy,(pt-p))/dot(dr.xy,dr.xy);
return length(pt-p-t*(dr.xy));
}
vec2 drToRo(vec3 dr,vec2 uv) //convert cartesian to rho/theta
{
float dist = linePtDist(vec2(0),dr);
return vec2(dr.z,atan(dr.y/dr.x));
}
Where is the bug? and how to reverse.
Thanks!