defining a circular area for mousclick within LCD

Dec 26, 2009 at 7:57pm

defining a circular area for mousclick within LCD

Hi.

I was wondering if anyone here could help me find a solution to my problem.

I have created 12 framed circles, each embedded within the other. The smallest being 0.1 and the largest having a radius of 1.0. Creating 12 rings within LCD. I am trying to work it out so that when I click within the bounds of one of these rings it will fill. I am having difficulty translating the LCD Cartesian coordinates into an area that has an arc for a boundary. How does one define an area that has an arc?
I can manipulate the mouse coordinates so that anywhere I click within the LCD it would always return the coordinates at the dead center of LCD (and circles).
From there I just need a way to determine a circular area size from center and check whether the mouse event happens within the bounds of that area.
I’m just not sure how to go about doing this :(
Any help or example would be greatly appreciated!
Thank you for your time and attention!!
~W

#47424
Dec 26, 2009 at 10:27pm

Hi !
It’s cosinus/sinus thing…
Have a look there : http://en.wikipedia.org/wiki/Trigonometric_functions
I’m pretty sure you’ll find what you need.

Otherwise, if you post your patch or at least an example of your exact thing, we may get you directly the formula. But I guess to fiddle with the patch, it’s better if you get by yourself how you can translate from cartesian to circular coordinates.

In short and if my trigonometrics memory is correct :
when x and y are your cartesian coordinates and (x0,y0) the coordinates of your centre, the radius r is
r = sqrt((x-x0)^2 + (y-y0)^2)
and θ being the angle :
tan(θ) = (y-y0)/(x-x0) that is θ = arctan ((y-y0)/(x-x0)) modulo π

Cheers

[EDIT] Did’nt mention it because it seemed obvious but maybe it is not… For your problem, once you get the radius of the mouse, you only need a multiple split corresponding to the radius of your different rings and you’ll know in which ring is your mouse.

#170654
Dec 26, 2009 at 11:22pm

You can easily convert x;y cartesian coordinate in polar coordinate with [cartopol] which does exactly the same things as BenCello said… with only one object

#170655
Dec 26, 2009 at 11:31pm

Ow…
Alright, much typing for nothing. I didn’t know [cartopol] without the ‘~‘ exists.
Then you’re done W ;)
Thank’s Kyred

#170656
Dec 27, 2009 at 7:22pm

Hey thanks guys. I got it working. I actually was doing this with the JSUI object and Javascript so Ben, your post helped me a great deal. It was easy to translate it into the script that way. I only posted in the main max forum because I felt like it wouldn’t be seen in the Javascript forum.
thanks for the link too, I now have a good understanding of these concepts and feel good to have learned something new! Max is so good for that!

Funny thing is, is when i executed the code:

var radius = Math.sqrt(real^2+imag^2);
var theta = Math.atan2(imag,real);
var deg = theta/Math.PI*180;
var output = [radius,theta,deg ];

within the Javascript, the results were
different from when i ran the same variables through the Cartopol object. The Cartopol object returned the more solid results so my solution was to script a Cartopol from within the JSUI and send the variables through it, then back into the JSUI and finally delete the object on the up click. It seems like a little much but it works perfectly. I wonder what is different between the Cartopol and the equations.

Anyway, Thanks again guys for your responses!!

~W

#170657

You must be logged in to reply to this topic.