How to Detect if Inside Ellipse?
-
@ericchesek As @Christoph-Hart said, just a wee bit of trigo will do the job.
But thegetIntersection
method won't work with a closed shape. It needs to be fed with a line, not a point, meaning it necessarily crosses a shape at minimum two places, leading to weird results.HiseSnippet 1027.3ocsV0uaiSDDecRMPLbBpDO.V2e4HxYbZu6.oCDsMMAEAsWD43DRmpNs0dR7ptdWy50MMB0GDdi3wg2.XV+Qsy0zSnHNqDmLet+1wy7a8LkLDxxjJhUuWsNEHVel870Bc7nXJSPldJwZe6ILQzXNmklAGq.J4j0ozrLHhXY08GMtY0aORw0e+CmP4TQHznhPdsjEB+LKgoazN6nehw4SnQvqXIs79oGMMTJFI4xbDRcsCHozvqnKgyoF25XSr9nwQLsTMWS0PFwZuSjQqmGKWIJ8+0rL1kbvHLjLGSTo5IRdjAwFsjQwLdzr5sdFAyxrlBQ2xBwWZeFKhcm9lBxWTXvsIh10CqNaButa.ugsgWPK3sEHY0BR6UBo8smGpXo5FKF77o1SEZPsfhk81PozWRm+rq8HI5gP6mPuBlnPg6hv64AACbwa8egC5UljC9gbfp7PENN3CiLs60Tk6LA286cqSzRPORljJEnf2iQaO13di2PY6xLYFFzadVv.7yvfhuWXxKFgeFnmg0T8uHy0LA3sHWDpYRg2x9N+gSOSZRasjgXqmFlQ0wFn0K0mFU2U50rbFSN8VZRdYWjW4OY9qhYZvXdoejhtpHQoCbSM6kSj4hnLug9A8G3ZtWjE1BWOcLKyOhpo9rrohLVDz2oGhtMVhfaN7vEEWl.QSKvl6GZALtbqys8aUFNSlmAinb9kXydSc.tF22E0BCRJj7ikWCpJHXpPJZDK2TjaJAu4fK95CL3nxkPLNEXdNzxmfKb+ppfGf9gWtsSwvFyW7hZ6U4iChk5XrMJYTclOC2q9Y+tR6U+uJ3di6SpVebE6i47crutw9vKJJMFTe+hNtF2aY+tJ.1NHEjZZo7ZWjcpKntRw4RM7RgWQQ04VG220zhEa0loGTI4bPsUyFNL06KPOQdxkfZ.Navyg6bDGr2jsv9gYKZSlEVNRzxQoXpfoeYJHdHJNR0bD9uec5oXs0PwToC8KETZlABVmBWi70kDN8rOExtRKSK7sZdmX8w5BqOplNhJ.NggjN11XGM4lF9b1QqaKrhEoiQ2r9KTLFXKi00RX2ubU8L.hiO29XN2sQA49zgHQrLJmS0axNaNRpx.9PXCJQCsG1OoW29Hq+2nr+uBw8smwzgwaGic1BFwGUeHvX0AcOxd7hEPntAf6YO429vbpFojreIRCnXXeh844IyQJzP.WcA1FYFBr5XZWKkCLxlJvbPDUH7O3UkwgFYqJiCqMRRngJ4aCKG8LGk9IEZPLIJdKhd1mYjcGRJFGMssA9AjD7T82FFZ19OAmf1dLGrCwb3NDyS2gXd1NDyy2gX9lcHlu88Fi4EpNNWKSJGGPEyFWvQYYMVPwNqhtPx+B4GF9wB
const var Pnl = Content.getComponent("Pnl"); const var ellipsePos = [50,50,100,100]; Pnl.setPaintRoutine(function(g) { var p = Content.createPath(); p.addEllipse(ellipsePos); g.setColour(Colours.white); g.drawPath(p, p.getBounds(1.0), 1.0); if (this.data.isInside) { g.setColour(0x33ffffff); g.fillPath(p, p.getBounds(1.0)); } }); Pnl.setMouseCallback(function(event) { if (event.hover) { var radius = ellipsePos[2]/2; var centre = [ellipsePos[0] + radius, ellipsePos[1] + radius]; var lengthFromCentre = Math.sqrt(Math.sqr(event.x - centre[0]) + Math.sqr(event.y - centre[1])); this.data.isInside = lengthFromCentre < radius; this.repaint(); } });
-
@ustk Yeah this isn't too bad! Nice solution and thanks for the help. :)
-
@ulrik This is really helpful too! Thanks!
-
@ulrik I couldn't help my self to explore this area a bit more so, in this snippet I have a function to find which area/areas is hovered (they can be on top of each other as well), so I have the rectangle and the ellipse but I couldn't find a way to get the precise area of the triangle
So if anybody with a magical knowledge of trigonometry (ustk?) could point me in the right direction I would be grateful!The difficulties with the triangles (for me at least), how to find out if hovered inside or outside the triangle because of the radian.
HiseSnippet 1683.3ocwXstaaaCEVJIZaxqEaEXO.D9GcxsoN1NosCIsq49VvZRMZxJFPQPKi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spW5wAPP68L2UYaumjBYVlrPq+EqprKZ
-
@ulrik Well, getting the area of a triangle is possible with trigo but not an easy thing (I don't know how from the top of my head though I tested a while ago two mathematics way of doing it)
From here, seeing the particular shape you're using and that you are going further than simple ellipse or rectangle, the solution would be the implementation of a Juce function to detect if inside the path. (a different one than getIntersection). Then it'll be very easy and less mind torturing (even if I like that ) -
@ulrik Stupid me... I already added it along with
getIntersection
It'sPath.contains(point)
HiseSnippet 931.3ocsV8uaaaCDlxIbsVaEaAnO.B8uT.7Dr6OGPQQahi8fQaREp6JJPQQAizYKhPQJPREWig7LrW08FrcTxNRd0oXvn0v1w2ceG4GO9cmRrVk.FiRS7591kE.w6mnSWJsYCyXbIYxIDuCni4xzQBAuv.GoAF43kELiARIdd686NXdc2mT85ue9wLASl.MtHj2o3Ivq34bai23W7RtPLlkBukm2B8CewjDkbnRnJQJsGsOofkbAaNbFyAqCk38CiR4VkdpkYACwa+iUoKmloVHqw+Ntget.bFCHSwEp18XkH0wXmWxvLtHMd8Q2PvUItoPrWcg3tzS4o7q82TP9kp.AMYztd30YS5s2FzaPa50uE81Bk7ZQo8qozAzoIZdgsIhiO+HchzB5YLrr2lJ0XIc9qNzgJDgzFkyt.FqQiqyH7w862K.+5vm5inLJADkH.lNDc36iWFFavkLcPrTD7rf0KzbvNTkWnjnQ38vX2yAuAcQKrInlwBwLalaMKhXooX0QG9gGfaM94i8BdD9Fow8cbwwDebEiLfMFq412nJsbIDNqTlX4JY37C8+S+tyc.pUJg0+wDsHiaALeLXplsnZOK5ET336wpRYpIbPT+C6E39Fg42kOKHzlwMQoLKKhalHM7T3P+t3Nr0sXIHDpEtjwvyPQ7MsINHW4eUqSyopRCLjIDmiZ5liCbIVkpNReIQvxXQDVVsXgvD9gJnQetWP8OV9Q2lTkkFJb0JWEtZK88Wu9AJ4YJK7ZYX0d3ekev+MzrYaMl6BTqDBPu0vtNW8WKwPYY94ftGpHDkv0.Q47l8HzatGocKbRsdpEPkbhjaecAHuoFaxJQH9q+XxIXk00XsxGhq.zVtiBdm.WhSopay5ROALWXUEUXWoxId2xVE8NqaBYRPP3XqFkhWvjO2dl2x1FK3o1LDl266PHY.edlcsEyIlVKIPd7yziDhfFGjubH.N9QkVJX1MmI4FDuJ.dIrwf.WyNplrKaOn9a1fp+uT7.ZL2ljscN1YKbDup9dvwUi2uCczrYPhsgf6SG+9uOyxI0ivleJyp4nNgdVY9TbZRBf6tDkQtl.uNN4ZscemsqBLEjoUF+C9ZUvANauUAGrNHImknUeJot0y8.jaW4A4jr5Ymcom5rCFPpZGcx19Q8I43yx9TRh63+qXGz1y496PNOXGx4g6PNOZGx4w6PNOYGx429p4392HNpzpxqaGPGwiplQ44MRxPkUkJj7u.xPkoEC
-
@ustk Nice one
-
@ustk nice job!
-
@ustk Would it also be possible to add text to follow a path you think?
-
@ulrik Alright... It's official... I'm drinking to much...
HiseSnippet 1266.3ocsV8uSaaDG+Lf2VxV0FR6A3HRSxoDL1.kUozpADfonU.qFV6lPnpC6K12v4NqyWJMah+YuE6sYOR6MX66c1l3.oUSQsVJN999i66m66Ou.oHjlmKjHqFmOIihr9J6AS3pjdIDFG0+Pj0p1Gy3QGklxxxo6KoDzASxH44zHjk0x+nVLqFqfLO+yOb.IkvCoSIgPuRvBoufMholRMXuehkldLIhdNaTMo2Yu9gBdOQpXL.oks8PYjvqIwzSIZwVxFY8YGEwTB4.EQQyQVqbfHZxfDwM7B4eEKmcUJUuvGM.1nBxGKRizHVSE0KgkFETczyQvtDL0Qrbgi3asOgEwti9TGx2XXfmpQc+g0RyBukmAd90gmWM3MGHYUCRqT.oUsGDJYYpobz34Ks6yUT4PB31qCkBYQK8W118DfDbk6Hx0zikvh6zvYWOuNX3U6tMAoxEoT2vTJQ5.DZBwhbE9sDINfmheNtZehopdhQYBNrvoEvqEHM7maDQQbI73TJHs2L6PVM8CgzHEMfnRtmYTz2o.4Z8qTRRRxZqsF90RlhwiwBNlfy.MvrbblH23FwpDB+5brRfgDF7PIixivAS.xwBIAX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4
-
@ustk Hahaha....beautiful!!! cheers
-
Hahaha this is incredible. Excellent work!
-
@ustk Just to be clear, this only works with paths and not fillEllipse or drawEllipse, for example? If so, is there an API reference for what shapes can be made with paths? Similar to what you did with
const var p = Content.createPath(); p.addStar([300,300], 5, 50, 200, 0);
-
@ericchesek in the API you'll find this
-
@ulrik Hmm, maybe I'm on an older build. 3.0.0, build 650, 2023 April 3.
I only have a fraction of these options in the "Path" API list. I'll look into it. Thanks! -
@ustk said in How to Detect if Inside Ellipse?:
Alright... It's official... I'm drinking to much...
Maybe I'm not drinking enough
-
@Dan-Korneff said in How to Detect if Inside Ellipse?:
@ustk said in How to Detect if Inside Ellipse?:
Alright... It's official... I'm drinking to much...
Maybe I'm not drinking enough
:clinking_beer_mugs:
-
@ericchesek April 3 is the date you built, not the branch date. I've implemented the new methods before that so you probably have to build the develop branch again