BlueMirage
Trust, but doubt.
- Reaction score
- 39
Well, as understood from the title (psyche), if I have several points which form a shape, how can I pick all units inside it?
I'ma go draw a picture in paint. brb
Alright, I think I have a solution. Kind of.
Assume that your unit is centered on Origo. 1 is the first point of your shape, and 2 or 3 are the second (Two examples).
For the first example, make a line between 1 and 2, and create the function (y=f(x)) for it. For this example, if the point where Y = 0 is on this line, then the unit is inside the first line of your shape. If it however is not, then the unit is not inside the shape at all.
The line between 1 and 3 would generate a line that would not hit the point where Y = 0, so the unit is outside the shape.
If two points are in the same quadrant, the unit being checked passes and is inside the line being checked.
Obviously, if you check for either X or Y depends on which quadrant the first point is in.
Loop this for each point in your shape, and you should get if the unit is inside or not. Note that each point must have a number so that you can pick them in the correct order.
It might not be the most effective method, but it's the only one I can come up with.
I'ma go draw a picture in paint. brb
Alright, I think I have a solution. Kind of.
Assume that your unit is centered on Origo. 1 is the first point of your shape, and 2 or 3 are the second (Two examples).
For the first example, make a line between 1 and 2, and create the function (y=f(x)) for it. For this example, if the point where Y = 0 is on this line, then the unit is inside the first line of your shape. If it however is not, then the unit is not inside the shape at all.
The line between 1 and 3 would generate a line that would not hit the point where Y = 0, so the unit is outside the shape.
If two points are in the same quadrant, the unit being checked passes and is inside the line being checked.
Obviously, if you check for either X or Y depends on which quadrant the first point is in.
Loop this for each point in your shape, and you should get if the unit is inside or not. Note that each point must have a number so that you can pick them in the correct order.
It might not be the most effective method, but it's the only one I can come up with.