Inside ondrawFrame() method of renderer:
session.update();
Pose camera = frame.getCamera().getPose();
Pose anchor= anchor.getPose();
float x = anchor.tx() - camera.tx();
float y = anchor.ty() - camera.ty();
double theta_g= Math.atan2(y,x);
value returned by theta_g is not correct, stuck here since a long time
I solved it through lot of trial and error ,once I focused on logic and coordinate changes it was easy :
float[] zcam = camera.getZAxis();
float g_x = (anchor.tx() - camera.tx());
//float g_y = ( 0 - camera.ty());
float g_z= (anchor.tz() - camera.tz());
double distance_left= Math.sqrt((g_z*g_z)+(g_x*g_x));
double theta_g=Math.atan2(g_z,g_x);
double theta_c= Math.atan2(-zcam[2],-zcam[0]);
double w = (theta_g-theta_c)*180/3.14;