Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithmic question: Best angle to view trees from fixed camera [closed]

I was asked this question in an interview, have no clue how to solve it. "Given a fixed camera in a forest (with predefined trees), give the best angle in which the camera pictures the maximum of trees" How would you approach it or at least what questions would you ask to get more requirements?

like image 434
JDD Avatar asked Nov 21 '19 14:11

JDD


2 Answers

If trees don't obscure over trees then:

  1. Sort all trees by angle around the camera position.
  2. Use sliding window approach to find direction to look at.

If trees can obscure other trees then the second step is a bit trickier.

like image 60
Yola Avatar answered Sep 21 '22 10:09

Yola


the idea is this:

  1. convert the list of tree coordinates to a list of angles.
  2. sort the list of angles
  3. use a sliding window to find the starting and ending indices that maximize the number of trees.
  4. note: because the best angle to position the camera might actually be very near the 360 degree, you need to take into account trees on the other side of the 360/0 line. The easiest way to handle that is to add duplicate trees to the list (in step 2) with a 360 shift. for example, a tree in degree 10 would be added twice, at degree 10 and 360+10. you don't actually need to add ALL the trees twice - you only really need to duplicate trees in the range 360+camera_angle, but its easy to just duplicate all the trees and it doesn't hurt.
like image 29
FuzzyAmi Avatar answered Sep 19 '22 10:09

FuzzyAmi