Below is the code which I have tried. It gives me the desired result but it is not optimized like camToPlan or MagicPlan app. In CamToPlan app center node moves very eficiently as per camera movement. If the camera is tilt the anchornode distance changes. How to achive the same in below code?
Camera camera = arSceneView.getScene().getCamera();
Vector3 distance = Vector3.subtract(camera.getWorldPosition(), vector3CirclePosition);
float abs = Math.abs(distance.y);
float newAngleInRadian = (float) (Math.toRadians(90f) - (float) camera.getLocalRotation().x);
float zCoordinate = (float) (abs / Math.cos(newAngleInRadian));
Log.i("1", "zCoordinate::" + zCoordinate + "::" + abs);
Vector3 cameraPos = arFragment.getArSceneView().getScene().getCamera().getWorldPosition();
Vector3 cameraForward = arFragment.getArSceneView().getScene().getCamera().getForward();
Vector3 position = Vector3.add(cameraPos, cameraForward.scaled(zCoordinate));
redNodeCenter.setWorldPosition(position);