Android Question Circular touch detection?

persianpowerman1

Active Member
Licensed User
Longtime User
hey guys... important question... please see the grafic i explained...

if i need to know if a particular part in any panel/activity etc etc is touched then... its not difficult when the part i need is in rectangular shape..

Now what if i wana detect which part of the circular menu has been touched??
do we have any routines? libraries? or any collision detection similar functions that i could use to know if that point exists in a particularly shaped boundry.. eg.. a round button..?

or else i would just have to use my own ideas from coordinate geometry...

what say? any ideas guys
 

Attachments

  • Graphic1.jpg
    Graphic1.jpg
    41.9 KB · Views: 269

Informatix

Expert
Licensed User
Longtime User
The best approach is to calculate whether the touch point is inside one of the polygons of your wheel. But there are two possible tricks:
- color each slice of the wheel with a different color then test the color of the pixel under the finger.
- stack panels containing the slices (a slice per panel). If the click is on a transparent part of the panel, the event is ignored (in Gesture Detector, you return false for the touch event). So the event is dispatched to the next panel. And so on.
 
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
the panels is a hilarious work around.. but well thought of!

but i think the get pixel color is really cool... how to i get the pixel color though?
thanx a million: )
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
the panels is a hilarious work around.. but well thought of!

but i think the get pixel color is really cool... how to i get the pixel color though?
thanx a million: )
The stevel05's class is probably a better choice. Anyway, to get the color of a pixel, you just have to call the GetPixel function of the Bitmap class.
 
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
Hey guys thanx a lot... been a great help.. but heres the problem

Steve... its dam smart... i got all the concepts... still sorting out the polygon one...
However... Informatix's get Pixel color.. is so cheeky and quick...

i have a button... i've attached its look...
the Get Pixel is a problem cz i have lots of them with vignettes...
the Hotspot... doesnt have these mix type shapes... or do you think i will have to use the polygon for the red type buttons i have shown??

what say?
 

Attachments

  • myButtons.jpg
    myButtons.jpg
    20.4 KB · Views: 244
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It depends how accurate you want the touch to be, and it depends how big the buttons will be. You may get away with approximating each button with three circles. If not, it'll have to be polygons. But again an approximation will probably be good enough.

If really approximate is good enough you could put a rectangle around each button providing you add the large middle circle last, that will be returned when it overlaps.
 
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
yea steve.. thats right... i did realize that for a button an approximation is good enough : )

however. .. when still on this topic. ...
i was really wondering that how do game programmers pull off the coding for collision detection? .. when accuracy is needed?..

could it just be a higher number of polygon points?
something like squaring a circle?
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
i was really wondering that how do game programmers pull off the coding for collision detection? .. when accuracy is needed?..

could it just be a higher number of polygon points?
something like squaring a circle?

Yes, they use polygons (with as many points as needed) and they detect whether the visible polygons overlap. To avoid complex computations, they always use convex polygons. A concave shape is splitted in many convex polygons. Look at this:
car_6-png.19410

You can see the polygon summits and how the vehicle is sliced in 9 convex polygons.
 
Last edited:
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
Wow.. thats some thinking.. thanx Informatix... and yeah... concave polygons do pose a lill more calculating...
thanx for sharing...

ok... so for now... i am going to work out the theory behind "Whats the logic used for Point in Polygon(pip)"!
... the reason behind that code in HOTSPOT

lets see should come up with something... will let you and Steve know...

tc man
 
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
OK guys... i finally Cracked the Logic behind PIP in the HOTSPOT coding..
read up a little from the net... and derived the final equation through coordinate geometry!

check it out...
steve .. informatix ... lemme know what you think... its brilliant.. who ever originally thought of this .. was a genius ;-)

the logic revolves around that tough part ie...
B4X:
(testx < (vertx(j) - vertx(i)) * (testy - verty(i)) / (verty(j) - verty(i)) + vertx(i))
 

Attachments

  • logic.jpg
    logic.jpg
    55.6 KB · Views: 225
  • derive equation.jpg
    derive equation.jpg
    273.7 KB · Views: 234
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes!, thanks for that. I understood the concept but the maths eluded me. I can follow that example, you learn something new every day :). As you say, genius.

I've stored the diagrams with my source code so I can refer to it if I need to.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Upvote 0
Top