I want to find the edges of a square depends on the position of the player.

Here is a picture of what I'm talking about.

1, 2, 3 and 4 are ImagePoints. So depends on the player's position, the edges are different. In the left one, 3 and 4 are the edges, In the middle 3 and 2 and in the right 1 and 4 are the edges. There are overall 8 possibilities, I just showed 3 of them. I would appreciate if someone make a capx file and uplaod it.

I don't know if this is a good way to go about it though, in terms of efficiency or logic.

I've saved each imagepoints' angle difference from the center point to an array, then sorted the array to get the two points with the largest difference.

EDIT: Updated original capx to clean it up, and now also works for any number of imagepoints/vertices.

I don't know if this is a good way to go about it though, in terms of efficiency or logic.

I've saved each imagepoints' angle difference from the center point to an array, then sorted the array to get the two points with the largest difference.

EDIT: Updated original capx to clean it up, and now also works for any number of imagepoints/vertices.

I guess it would probably be haelpful to expalin the formula.

Here's a general view for one corner. P1 is the current corner and P0,P2 are the previous and next corners. "A" is the location of the player.

A
/
/
P1----P2
| |
| |
| |
P0----+
So next I made the obsevation that the current point (A) would only need to be created if it's in either of these two regions (b or c).
.........
.........
bbbbbbb..
bbbbbbb..
bbbbbbb..
..cccP1---+
..ccc| |
..ccc| |
..ccc+----+
..ccc
.....
.....
To calculate which region I used a vector dot product to calculate a vector projection. That sounds more vague than it is but it looks like this. It works relative to any corner.
(A-P1) dot (P0-P1) < 0 and
(A-P1) dot (P2-P1) > 0
or
(A-P1) dot (P2-P1) < 0 and
(A-P1) dot (P1-P1) > 0
[/code:2mpj4t2g]
The rest was a lot of math simplification.