How to detect if a point is inside a 2D cone?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hello,

    This is more of a math question than anything, but I was wondering if anyone had any solution to checking to see whether or not a point is inside a 2D cone?
    This MUST be done without the use of ghimmicky Multimedia Fusion collision detection, and raw maths.

    Thanks so much to anyone who has any advice, an MFA would be extremely appreciated. :)

    Best regards,
    Jacob

  • you need something like a "point in triangle" I guess?

    There are quite a number of solutions involving various kinds of maths,
    but when I had to do this, the fastest / less convolute solution I found was making these two consecutive tests:

    1) check whether the point is inside the bounding box of the triangle

    if so:

    2) check whether the angle of this point to the origin vertex of the "cone" lies between the angle to the two other vertices

    if so >>> the point is inside

    (and from what you say you can't check a simple cone object with advanced collision overlapping a pixel-object right? XD)


    EDIT:
    now that I think of it, my situation was a bit simplified, and I could assume orthogonal directions of the cone,
    if yours can assume any arbitrary angle of the cone, you could have false positives like this:

    Please login to see this attachment.

    Those could be fixed with an additional test (which would still make for worse performances, if this can be an issue):
    3) distance of point to vertex not being higher than length of vertex perpendicular to the opposite side

    a selection of my Fusion examples can be found Please login to see this link.

    Edited 2 times, last by schrodinger (July 1, 2016 at 10:39 PM).

  • hi,
    yes, Ive used some shortcuts with action points / cone fixed width to speed up the preparation:

    Please login to see this attachment.

    not sure if this is more performant than a collision check though (I think probably not XD)

    what is your detailed use?
    you need to check many points inside a loop?
    is this related to the other thread you opened?
    (didn't have time to thoroughfully check that out :()

    a selection of my Fusion examples can be found Please login to see this link.

  • Thank you very much for the example! :D You know, I never even knew that X Right, X Left, Y Top and Y Down, etc even existed. Isn't this basically the equivalent of collision detection though?

    Yes this question is linked back to my other thread: Please login to see this link.
    This thread goes into detail about the "no effect on collisions" bug. It would appear that my dynamic light engine is checking whether or not it is overlapping against not only backdrops that aren't obstacles, but backdrops on other layers as well. I can only assume that this is a bug with MMF2. Please take a read of my other topic and perhaps watch the YouTube video that's in there too, it's pretty simplistic to understand what the issue is (there's an MFA there too).

    On the topic of the cone, this was an idea I had as a solution to my problem of replacing "overlapping with backdrop"... Instead, I wanted to create my own dynamically create my own active objects for my lighting engine to overlap on the walls. So, if any walls are in the cone, it temporarily creates an active object that blocks the light there. So that my lighting engine is not checking for collisions against obstacles.

    If you don't understand what my idea for a solution is, it would look something like this: Please login to see this link.

    So as you can see active objects would be created and I would be testing my collisions against much fewer objects (backdrops have thousands of objects, whereas active objects will only have between 50-100).

    The points will come from my Array object that loads in the map.

  • Quote

    Isn't this basically the equivalent of collision detection though?

    Don't know actually! Don't know how Fusion handles collision detection, but given the fact they support any complex shape with fine detection,
    I think they somewhat loop throughout the entire mask (overlap) or mask perimeter (collision)

    This is a "special case" (a triangle, and a particular one) and should require fewer tests
    but don't know about speed of handling expressions vs speed of builtin fine detection.

    Quote

    So, if any walls are in the cone, it temporarily creates an active object that blocks the light there

    I fear this would be much more expensive (creating a whole bunch of objects every frame) :(

    Do you have MMF or CTF?
    Not sure I get same results on mine, but seems like the array map you supplied is not loading the floor that causes your issue, or maybe I've missed something.
    but going to answer on this in the other thread!

    a selection of my Fusion examples can be found Please login to see this link.

  • I use CTF, I'm just used to calling it MMF. :P

    Yeah I agree with you, I think that creating a bunch of active objects would be more expensive too. :/ But this is so stupid! If only my lighting engine dot thingy WAS NOT testing for collisions against backdrops on other layers that aren't even obstacles, there wouldn't be a problem. -.- Hopefully there will be a patch for this bug.

  • Have you verified your hypothesis by removing the backdrops in the other layer to see if you gain speed? If so, you should make a simple example of it and put a bug in bugbox so Clickteam can fix the issue.

    Please login to see this link.

  • perfect example. BTW, it might be a pain and a bit hacky, but have you considered putting non-collision backdrops into a layer below the game layer? I am curious if the same slowdown occurs.

    Please login to see this link.

  • Yeah, specifically relating to my game itself:
    Layer 7 - GUI
    Layer 6 - Players, walls, entities, collisions, etc (only collidable backdrops here)
    Layer 5 - Dynamic light surface object
    Layer 4 - Decorative layer for backdrops (no collisions)
    Layer 3 - Decorative layer for backdrops (no collisions)
    Layer 2 - Decorative layer for backdrops (no collisions)
    Layer 1 - Decorative layer for backdrops (no collisions)

    In my map editor I'm pasting a lot of floor tiles on layers 1-4... Whereas the obstacles are being pasted only on layer 6... If you wanna check out my game and map loading engine for yourself, then check my other thread:
    Please login to see this link.

    And I put an attachment to the .ZIP file with MFA included in there.

  • the bugbox link is:
    Please login to see this link.

    since you would better do this anyway,
    if you want to report the issue to the bugbox:
    have you tried making a simplified .mfa just to test the issue,
    like making a blank project with just:

    1) paste backdrops - test collision onloop a zillion times
    2) no paste backdrops - test collision onloop same zillion times

    and see how that affects framerate?

    If the issue reproduces on a simplified scale,
    would prove none other part of your code is causing that,
    and provide a quick way for Clickteam to test

    if the issue does not reprduce - then this file may anyway help you backtrack where the issue was

    a selection of my Fusion examples can be found Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!