I'm looking for a fast way, preferably without trigonometric operations (just multiply, divide, add, sqrt and subtract) to determine if a point is visible. E.g. say I am facing 0 degrees N, I am at 51.40,-1.08, the camera has a HFOV of 30 degrees and the point is at 51.20,-1.085 it should return TRUE, because the point would be facing me and is within the 30 degree FOV.
It's required that it returns TRUE (false positive) instead of FALSE given edge cases, otherwise points may be hidden when they are actually visible. Currently I have my augmented reality project using atan2 to calculate the actual angle but if I can shave calculations off from points which are definitely not visible every little bit helps. I only need it to be accurate over distances of less than 2 km.
Here's my code to calculate horizontal and vertical position. It's only accurate over <5km distances but accuracy isn't critical anyway as those waypoints aren't drawn. This project is open source, so it's okay for me to post a lot of code.
res->est_dist = hypot2(p_viewer->p.lat - p_subj->lat, p_viewer->p.lon - p_subj->lon) * 2000.0f; // Save precious cycles if outside of visible world. if(res->est_dist > cliph) goto quick_exit; // Compute the horizontal and vertical angle to the point. res->h_angle = angle_dist_deg(RAD2DEG(atan2(p_viewer->p.lon - p_subj->lon, p_viewer->p.lat - p_subj->lat)), p_viewer->yaw); res->v_angle = RAD2DEG(atan2(p_viewer->p.alt - p_subj->alt, res->est_dist)); // constant scale factor: needs to be adjusted // Normalize the results to fit in the field of view of the camera. res->h_angle += p_viewer->hfov / 2; res->v_angle += p_viewer->vfov / 2; // Compute projected X and Y position. res->pos.x = (res->h_angle / p_viewer->hfov) * p_viewer->width; res->pos.y = (res->v_angle / p_viewer->vfov) * p_viewer->height;
See that call to atan2 for the h_angle? If I could eliminate it by saying "this point is definitely not visible" it would be nice.