## Maths question: proximity to centre of ellipse

Apr 24, 2010 at 3:42pm

# Maths question: proximity to centre of ellipse

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. –
#49979
Apr 24, 2010 at 8:44pm

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?

#179443
Apr 24, 2010 at 8:59pm

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!

#179444
Apr 25, 2010 at 9:44am

Hello maxers,

a way :

– Pasted Max Patch, click to expand. –

soon the polar one …

#179445
Apr 25, 2010 at 1:00pm

Hello maxers,

cartesian to polar :

– Pasted Max Patch, click to expand. –

HTH.

#179446
Apr 27, 2010 at 3:49pm

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.

cheers

-Tim

#179447
Apr 27, 2010 at 4:15pm

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).

HTH.

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).

#179448
Apr 27, 2010 at 5:08pm

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!

#179449
Apr 28, 2010 at 9:51am

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. –
#179450
Apr 28, 2010 at 10:22am

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!

#179451
Apr 28, 2010 at 12:22pm

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.

###### Attachments:
1. Ellipse.maxpat
#179452

You must be logged in to reply to this topic.