Detect if two paths intersect
-
Is there an easy way to detect if two paths intersect? I want to make a circular XY pad, but I want the outer perimeter of the draggable XY cursor (tiny circle) to stop at the pad's boundaries (larger circle). Ideally, the script would work for arbitrary path shapes.
I can check if the pad's boundaries contains my mouse cursor position while clicking or dragging, but that does not account for the shape of the draggable XY cursor. It also leads to a case where the draggable XY cursor stops in an odd position if I drag my mouse quickly outside of the pad's boundaries.
See the snippet for what I've done so far.
HiseSnippet 1359.3ocsW02SaaDF+LfaW7V2Vk1GfS8eVPxMDfR2jPSsk.LEsRaTSWEUHT0E6KNmv4NK6y.Vq7O6S19HsuAaOO2YmbYjzMgVQQDtmW+cOucOLHWEwKJT4DuVusJiS79J+gUR8jdSXBIo+gDuuz+nzTQVA+z2SNnJiUTviIddq+yn.ds1fX94Oe1ArTlLhOmDg7NkHh+RwTgdN0AO+WDooGyh4uUL0Q5m779QJYOUppD.y59cIYrnKXI7WwPwVym3cuihEZU9PMSyKHdabfJtZ3D0URq7uSTHFkxwCaSFBFxR9XUZLhXjJo2DQZ7flKcAArxf4gf0sgfuy+DQrXF84ghu0vfNWC23g2ZKBu0W.da6ButNvaIPxyARaXgzC8GFkKxzy4XSM8kZd9XFD1cghUVxZe8886o.Ij5NSYWvONGNLSi1Osa2PJ7qM2OHXqsnCXRdZ.jCJzzKY4zLY5oum9SzFKjv08TSyTR3P6GY39HP0OI6NEHUoNWk1iklNBxnsURCyZx0NuWNGhZTvgYrXJSFSiJygqoCd.8UWwiGvzSbPUjQQjXavTykNVoWoTf+NPjPiD4Qobvg5I21Mu.z.LvY6rWH7AhROdut0ec99ANXoCKNttAositV27RgVCtX4dBfXiW5F1MbW7CXafrqMqkpNNchprfSm.AnTgLIvDIwfrg9rP73RYjVnjs4WB29MC9sfVhwT6oNw4rD5G+H0dJJUDcAOdyfVfPsfOfSzSDETv9bZLWyizEzoF2loJDnYoWI.Qjfb7lvk4tERGUpoPEu0LwJZeJV2QEZ5Up7KnrB2rXGHTngVqh1LYEXbgTSExnzRncE9CL9rI8YfsP7zIloYcDE8kEhXNDyVpgNydotNz9c04PXq4VojoUvE4RtA2XTHgMBSNlBsUcm.cwP2sg.DwLgLGzcM.qZ.r+hbplwoB4biETF9QPxLgGC0k.oanA2TmoOLmcEpSdkdgL8.3hpeipDnxmmnSfjLnO1IwRiJSwlIrKp.FHUegU5uuvzf0jECZgUgHncuBOtot7rcNeqcfi6ruUvpEDrxQvcmIXPqjNigw6uHMsscTdQmjbdElFLnSWlaiw0c5pb712jCfxNgM+tXJXkY.LAjXGxfNalOsl0j7s.xz56TxDtP8CL65.UoLtn81c5tIp1MM.NFSCN.tdrzR85nzRiOcbIDhBO65vpv4A0v4gsy27Vto4hyvICPVFaCWk2fVcq6PsWxLnP5t.+lBp2vyvRGiWxvY8PGAMxNENPHM86M0SzEGR2NpYxdHL4Buk3HkYD6jaMMNaEBbNF4UJM+0x1FwCtIf9OYMd7R4U61Td9RYiKNj+oTrsrb5HdtKXQAgWSW7IZ+U+Ds6FDQ1WQbDTI6KE5WmwkqZuBR8SOve8q8ODJaw20qoAxkwy0BDBdGxuDVRx9JeK+C4EWnUYFYqitDu.sg6CZ1A.SdDA7R+88MYIx0tKcU4d3JQrdxLB+wu+7IbQxDsKESASySG.h9Fen6kNmvnjlkxZcu+B9AUSn4S+TT2wkL41qy.KRohwoTKtcEtRYMCHetvJM3ZKPWutxcky+2V45+JDen+.gNZxxw3ZKAiPV+yAFqWT8A9GMdL7.8b.tg+wm94YqTh8MmjSX5bATv4+pxoCgTcDG7tDpHw9Iu0vJe64t3YLBLjKiMGvBhZlaim8pYtcCSxTVTt5C0CkvUg+BCE.SRy+EPK+SvyzsIlNa237TXy7ODEsnotkh6bWUb26phO4tp3d2UEe5cUwe3tp3O9uqH9ON8hRsZpssgPNYvQlwhddGIw8vLUqj+FPM8iEX
-
@ericchesek measure the distance of your small circle from the centre of your large circle (simple trig) if >= radius of big circle then you are outside the big circle..
-
@Lindon Sure, I can do that, but it doesn't address the points in my original post about script working for arbitrary path shapes or the quick mouse movements.
If it has to be done with trig, so be it!
-
@ericchesek if you iterate over the dot.getLength() and get each point of the dots path
if any point is outside the large circle, set isInside to false?this.data.isInside = true; for (i = 0; i < dot.getLength(); i++) { var p = dot.getPointOnPath(i); if (!allowedPath.contains([event.x-p[0]+dot.getBounds(1)[2]/2, event.y-p[1]+dot.getBounds(1)[3]/2])) this.data.isInside = false; }
-
@ulrik That's an interesting solution! I came up with something a little different. Any XY cursor and pad shape I use is likely going to be symmetrical, so I have the XY cursor area bounds set to a smaller version of the XY pad shape. When the mouse cursor moves outside of the XY pad bounds, the XY cursor locks to the smaller XY pad shape path. Not perfect for all shapes, but maybe close enough for my needs.
That's probably difficult to read. lol. Snippet below.
HiseSnippet 1395.3ocsW0saaaCElJIpcVaEaEXO.D8lo.n4ZmD2Mffh0DmjAiszZT2UzBCiBFIZahHSJHQmDg0bydr1U6QZuAamCorMUiaVQvpgUh44O9wye7n94pXdQgJm303UkYbh2W4OnTpm1cJSHI8Nh38k9GmlJxJ3u4sjCKyXEE7Dhm2l+LJfWisHlO+8OcHKkIi4qHQHuVIh4+pXlPuhZ+m8KhzzSXI7WIl4H8dOqWrR1UkplCfYS+VjLV74rI7myPw1vm3cuiSDZU9.MSyKHdacnJobvT0kRq7uVTHNKkiKZSF.FxR9DUZBhXjJo6TQZR+EG5BBXk9qbAaZcAeq+ohDwR5qbEeigAckFt9CuMpCuMqAu1tvqkC7VCj7bfzVVH8P+Aw4hL8JN1PSOolmOlAtcWnXkkrwede+tJPBot4L147SxgEK0H7IsZEQg+r89AAO9wz9LIOM.hAEZ5ErbZlL8Muk9T5BKLgq6plkojvhvGY39HP0akcyBjpTmqR6xRSOChngJogYE4pMuaNG7ZTXCyXIQTPV0k7DJCHCqjIz344vo1AdWU1mom5fuXiIPhgfQWIXks9Dk1tOeTAQrdUoAW.R0SqAnCPpOkNbmNQv2NcZgOi1OvB0lrjjpJoPqrKN61szZNyuQQeIOVyjSR4gCAy0JZuVQsaMBw55DADnCvGj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