Unit enumeration within an arbitrary shape

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.

regiona.png


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.
 

The Undaddy

Creating with the power of rage
Reaction score
55
Ok find a function and a bunch of checks and it's done.

Actually I understood little to nothing form what you said.

>and create the function (y=f(x))

Do you mean to literally, having y = f(x) = ax + b, find a and b?

Secondly I think you got your 2s and 3s wrong

>The line between 1 and 3(sic) would generate a line that would not hit the point where Y = 0, so the unit is outside the shape.

But if my figure is 123 it's a triangle and (0,0) is within it's boundaries?How is the unit magically outside of it.

>each point must have a number so that you can pick them in the correct order.

Well they do, but I would need more explanation on the first part

Thanks :p
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
Points A. B and C

......A......
..............
..............
.B........C.
JASS:
set AB = Atan2(By - Ay, Bx - Ax)
set AC = Atan2(Cy - Ay, Cx - Ax)
set CB = Atan2(By - Cy, Bx - Cy)

set AD = Atan2(Dy - Ay, Dx - Ax)
set CD = Atan2(Dy - Cy, Dx - Cx)

if AD > AB and AD < AC and CD < CB then

        //Do Stuff

endif


Something like that? o.0
 

The Undaddy

Creating with the power of rage
Reaction score
55
@SineCosine

[del]I think that'll work perfectly, thanks[/del] :thup:

EDIT: I think I spoke too soon
..........B....
................
...A...........
..........D....
...............
..............C

Here AD > AC but still D is inside of the shape
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
I can explain that,

A has to always be on top
B has to always be at the bottom left
C has to always be at the bottom right

XD

Now..
......A......
..............
......D......
.B........C.
//////////////
......B......
..............
......D......
.C........A.
////////////////
......C......
..............
......D......
.A........B.
///////////////

Okay, I am going to type out something..
Give me time to give a better formula xD

[EDIT]
Okay, here goes..


JASS:
//These are all the things we need..
real Ax
real Ay
real Bx
real By
real Cx
real Cy

real Dx
real Dy

real BD
real BA
real BC
real CD
real CA

boolean Boolean1

boolean Boolean2

boolean Boolean3

//We are finding out if D is on the correct side of BA
set BD = Atan2(Dy - By, Dx - Bx)
set BA = Atan2(Ay - By, Ax - Bx)

if BA > BD then
     set Boolean1 = true
      // This is because we have shown that as long as A, B and C are always the same, you can orientate it however you want, but if D is within ABC, then in the result of BD and BA, BA will always be larger than BD
endif

//We are finding out if D is on the correct side of BC
set BD = Atan2(Dy - By, Dx - Bx)
set BC = Atan2(Cy - By, Cx - Bx)

if BD > BC then
     set Boolean2 = true
      // This is because we have shown that as long as A, B and C are always the same, you can orientate it however you want, but if D is within ABC, then in the result of BD and BC, BD will always be larger than BC
endif

//We are finding out if D is on the correct side of CA
set CD = Atan2(Dy - Cy, Dx - Cx)
set CA = Atan2(Cy - Ay, Cx - Ax)

if CD > CA then
     set Boolean3 = true
      // This is because we have shown that as long as A, B and C are always the same, you can orientate it however you want, but if D is within ABC, then in the result of CD and CA, CD will always be larger than CA
endif

//Tada!!

if Boolean1 == true and Boolean2 == true and Boolean3 == true then
     call BJDebugMsg("I AM INSIDE THE TRIANGLE")
endif


Just make sure you don't change your A, B and C the moment you set them, lol
I would upload an image explaining my logic, but..
I am a bit lazy =x

I won't guarantee it works..
But you can try xD
 

BlueMirage

Trust, but doubt.
Reaction score
39
Actually, in my example it's only a part of a bigger shape, disregarding which. In my example, the part is one of that shape's lines.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
You can make it apply to other shapes, arbitrary shapes.

Just decide on a path.

..A...................
...................B..
.............Z........
.D....................
.......................
...................C..

Just make sure you go one way, I suppose.
JASS:
//Something
AB = Atan2(By - Ay, Bx - Ax)
AZ = Atan2(Zy - Ay, Zx - Ax)

AB > AZ then return true

//Something
BC = Atan2(Cy - By, Cx - Bx)
BZ = Atan2(Zy - By, Zx - Bx)

BC > BZ then return true

//Something
CD = Atan2(Dy - Cy, Dx - Cx)
CZ = Atan2(Zy - Cy, Zx - Cx)

CD > CZ then return true

//Something
DA = Atan2(Ay - Dy, Ax - Dx)
DZ = Atan2(Zy - Dy, Zx - Dx)

DA > DZ then return true

If all of the above == true then
 //It IS inside that shape xD
endif

//I think..
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top