Forums > MaxMSP

Maths question: proximity to centre of ellipse

April 24, 2010 | 3:42 pm

I’ve done some forum and google searching, and found some info that I couldn’t quite wrap my head around.

If I have an ellipse drawn into [lcd ], how do I go about calculating its centre point, and the mouse proximity to this point, and test for a mouse-over of just the ellipse, not including its "surrounding rectangle".

All the calculations I found made vague sense, but it’s been such a long time since I had to do any that the solution is escaping me! Is this a situation where [cartopol ] might help?

Cheers, I know this isn’t going to be remotely complex for many people :P

– Pasted Max Patch, click to expand. –

April 24, 2010 | 8:44 pm

The equation for a circle is x*x+y*y=1 < => y=√(1-x*x). In the case of an oval this becomes y=√(1-ax*ax). If you work on a mac, there’s the beautiful application Grapher part of the utilities to get a visual representation. What you need to do is to find the solution of where the equation of your oval and a line through it’s centre point and the mouse meet and to divided the distance of the one by the other. Does this help?

April 24, 2010 | 8:59 pm

I’m not 100% sure I’m following you, but I’ll give it a go in a couple days when I have some more time.

I need to get myself an A-level maths book to jog my memory, then I’ll be ok!

Thanks for the help and the tip about grapher, I’ll check that out as well!

April 25, 2010 | 9:44 am

Hello maxers,

a way :

– Pasted Max Patch, click to expand. –

soon the polar one …

April 25, 2010 | 1:00 pm

Hello maxers,

cartesian to polar :

– Pasted Max Patch, click to expand. –


April 27, 2010 | 3:49 pm

Thanks for the replies.

Still not following the maths behind how this works….

@ pizza_olives, how do you calculate the values (175 and 125) that are in the [offset ] subpatch?

It’s probably because I’m really mathematically dense, but I can’t work out how those numbers relate to the co-ordinates used to draw the oval into lcd in the first place.



April 27, 2010 | 4:15 pm

Hello timlloyd,

ellipse is (300 – 50) * (200 – 50) long/large,
because rectangle up/left coord (50, 50) down/right (300, 200),
so 250 * 150 long/large,
half -> 125 * 75,
50 + 125 = 175,
50 + 75 = 125,
that’s to compute coordinates of ellipse’s axes (yellow / red -?- points on the graf), and the center of the ellipse (175, 125).


EDIT : first post is about pins-and-string method ("ellipse du jardinier") using focus, second about polar equation (from the center of ellipse, not from the focus).

April 27, 2010 | 5:08 pm

Ok, I’ve got that mostly working. There are a couple issues though, probably to do with how I’ve hooked it all up. I’ll go back through your patch and check it.

Here is a patch to demonstrate the issues:

– Pasted Max Patch, click to expand. –

Thanks for the maths help!

April 28, 2010 | 9:51 am

Hello timlloyd,

? Am i doing your homework ;-)

To sum up : usually : long > large ;
in case not : swap long and large then add pi/2 to the angle.
why ? wikipedia !

– Pasted Max Patch, click to expand. –

April 28, 2010 | 10:22 am

Haha don’t worry, my uni course only involves max/msp for learning about audio synthesis, not exploring the intriguing world of creating interfaces :( This is just something I’ve been messing with the past few days when I should have been doing my other work!

I had tried swapping long/large but without adding 2/pi to the angle, so it didn’t help…………I really do need to get back into maths……..Your A

Thanks loads for clearing up how this works. It’s going to be fun to play around with!

April 28, 2010 | 12:22 pm

Hello timlloyd,

I really do need to get back into maths …

It was the same for me … so a day i go back into my dusty school books, and finally it was no so hard as i thought …

i fixed few little mistakes in patcher names :
join the patch, in case of.

  1. Ellipse.maxpat

Viewing 11 posts - 1 through 11 (of 11 total)