Home > Mobile >  Finding two "bounding" vertices of a given polygon w.r.t. a known (light source) point
Finding two "bounding" vertices of a given polygon w.r.t. a known (light source) point

Time:10-23

Context: I apologize in advance of the non-rigorousness of the question, as it turned out to be harder to formulate than I originally thought. I'm going over different ways to find two "bounding" vertices in 2D space of a given polygon w.r.t. to a known point. In this context by "bounding" vertex I mean the situation best described by this image. I.e. let p be the known point and imagine that we place a light source at p. Then the bounding vertices of a polygon P(x_1,...,x_n) are those two points v_1, v_2 for which the connected line segment l(v_1, v_2)blocks the light from pin the same way as the whole polygon P(x_1,...,x_n) does.

Question: I already have a solution which compares vertices of P by the rotation angle w.r.t. to p. However this method requires using the trigonometric atan2 function, so I'm interested in knowing is there a computationally cheaper method.

CodePudding user response:

Choose an arbitrary starting vertex, let A. Now choose another, let B, and check if it lies to the left of FA. If yes, continue with FB and so on. Do this for left and right simultaneously.

The LeftOf test is a mere sign of a 2x2 determinant.

  • Related