Warning

 

Close

Confirm Action

Are you sure you wish to do this?

Confirm Cancel
BCM
User Panel

Site Notices
Posted: 9/21/2014 10:38:10 AM EDT
Greeting all.
Not sure if this belongs in this forum or the computing forum, so apologies if it's better suited elsewhere. For some reason (well, the fact that I am rubbish with geometry) I've hit a bit of a mental brick wall with this one.
First, a quick picture


(edited to add - just noticed I reversed the A/a and B/b points between the top and bottom pictures, darn it)

I have two circles that intersect. I want to use the second to make a cut-out from the first. I can work out the x/y pos for the two points where the circles intersect, A and B. The next step I am attempting to take is to draw the circle only between these two points. This is to be generated on the fly based on a range of different inputs, including differing sizes and relative positions of the circles, so I can't use my usual workaround of pre-drawn images.
This is something I am trying to do using Javascript - specifically the canvas arc() method [link] to draw partial circles. x/y pos is measured from top left in this case.
The arc method works by identifying "start" and "end" points in radians for the circle, which allows me to draw Circle 1 from point a clockwise to point b, and then draw Circle 2 from point a clockwise to point b.
So, for each circle, I need to work out the start and end angles in radians, with 0 in the 3 o'clock position. I also need to work out how to then translate this into javascript.
The bit of my brain that still works suggests I should be able to build a triangle quite easily based on the x/y pos of the main circle and the intersecting points - but I can only see this in the configuration above where both circles neatly align with both centers at the same y. The second circle might actually overlap from any direction and to any extent, and that's where I'm getting stuck.
Does anyone have any pointers or suggestions as to ways I might tackle this problem? I'm too used to using handy libraries to avoid any serious maths when writing programs, so this is a bit of a culture shock for me and I'm not even that conversant with the terms being used - my last geometry lesson was 20+ years ago
As always, any help is appreciated.
 
Link Posted: 9/21/2014 1:02:23 PM EDT
[#1]
Problem resolved, feel free to ignore and let this thread drift off into nothingness.



Just in case anyone else is trying to do the same thing, the calculations are all handled for you by Math.atan2()



Which is a good thing, because I was having a hell of a time trying to do this by hand

Link Posted: 9/21/2014 1:11:38 PM EDT
[#2]
Link Posted: 9/21/2014 2:14:29 PM EDT
[#3]
Was any of that op in English?   Wait, I guess it was 'cause I recognized some of the words....  
Link Posted: 9/25/2014 11:19:57 PM EDT
[#4]
OP's solution:

Close Join Our Mail List to Stay Up To Date! Win a FREE Membership!

Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!

You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.


By signing up you agree to our User Agreement. *Must have a registered ARFCOM account to win.
Top Top