Area of two circles' intersection

Two circles given, intersecting:

M(a,b) r

N(c,d) s

Equation of circle:

(x-a)^2 + (y-b)^2 = r^2

or

(x-a)^2 + (y-b)^2 -r^2 = 0

To find intersection points you equate equations of two circles i.e.

(x-a)^2 + (y-b)^2 -r^2 = (x-c)^2 + (y-d)^2 -s^2

find (x1,y1), (x2,y2) (two points)

Divide intersection to two chords, find one by one, add together voila!

PS: This is for enjoyment if you don't then don't bother to write.

Two circles given, intersecting:

M(a,b) r

N(c,d) s

Equation of circle:

(x-a)^2 + (y-b)^2 = r^2

or

(x-a)^2 + (y-b)^2 -r^2 = 0

To find intersection points you equate equations of two circles i.e.

(x-a)^2 + (y-b)^2 -r^2 = (x-c)^2 + (y-d)^2 -s^2

find (x1,y1), (x2,y2) (two points)

Divide intersection to two chords, find one by one, add together voila!

PS: This is for enjoyment if you don't then don't bother to write.

Well I'm intrigued, but the last line confuses me, perhaps if you drew a pic showing what you mean by "

*Divide intersection to two chords*"I meant two calculate areas I and II seperately(i'm not sure if it can be done all together at once) in the figure. And i wonder if the areas can be calculated with integrating

A more direct approach via geometry (but requires trig functions)

For clarity, and without any loss of generality, I'll assume that r > s and the center of circle "s" falls outside of circle "r"

We are interested in the area of circular *sections* A1 + A2

Let:

L^2 = (c-a)^2 + (d-b)^2 (ie, L = the distance between circle centers)

2u = The angle of arc subtending the chord from circle "r"

2v = The angle of arc subtending the chord from circle "s"

Then, using the cosine law:

2*r*L*cos(u) = r^2 + L^2 - s^2 (from sircle "r")

2*s*L*cos(v) = s^2 + L^2 - r^2 (from sircle "s")

We can solve for u and v from these equations (via arccosine) since r, s, and L are known.

Compute the areas of the circular *sectors*

Ar = Pi*r^2*(2u/2Pi) = u*r^2

As = Pi*s^2*(2v/2Pi) = v*s^2

To compute the *sections*, we need to subtract the triangluar portion of the sector:

Tr = 2 * (1/2)**

= (1/2) r^2 *sin(2u)

similary

Ts = (1/2) s^2*sin(2v)

The area for the *sections* are

A1 = Ar - Tr = u*r^2 - (1/2) r^2 * sin(2u)

= (1/2) r^2 [ 2u - sin(2u) ]

A2 = As - Ts = v*s^2 - (1/2) s^2 * sin(2v)

= (1/2) s^2 [ 2v - sin(2v) ]

We note the need for the angles to be expressed in radians.

The total area of intrest is A = A1 + A2.

For clarity, and without any loss of generality, I'll assume that r > s and the center of circle "s" falls outside of circle "r"

We are interested in the area of circular *sections* A1 + A2

Let:

L^2 = (c-a)^2 + (d-b)^2 (ie, L = the distance between circle centers)

2u = The angle of arc subtending the chord from circle "r"

2v = The angle of arc subtending the chord from circle "s"

Then, using the cosine law:

2*r*L*cos(u) = r^2 + L^2 - s^2 (from sircle "r")

2*s*L*cos(v) = s^2 + L^2 - r^2 (from sircle "s")

We can solve for u and v from these equations (via arccosine) since r, s, and L are known.

Compute the areas of the circular *sectors*

Ar = Pi*r^2*(2u/2Pi) = u*r^2

As = Pi*s^2*(2v/2Pi) = v*s^2

To compute the *sections*, we need to subtract the triangluar portion of the sector:

Tr = 2 * (1/2)**

= (1/2) r^2 *sin(2u)

similary

Ts = (1/2) s^2*sin(2v)

The area for the *sections* are

A1 = Ar - Tr = u*r^2 - (1/2) r^2 * sin(2u)

= (1/2) r^2 [ 2u - sin(2u) ]

A2 = As - Ts = v*s^2 - (1/2) s^2 * sin(2v)

= (1/2) s^2 [ 2v - sin(2v) ]

We note the need for the angles to be expressed in radians.

The total area of intrest is A = A1 + A2.

I forgot to say something, sorry:

I know how to calculate but thanks either, this thread is much more like the threads The Svin's math book ...

You should submit your code and let it optimized or sthg like that.

I know how to calculate but thanks either, this thread is much more like the threads The Svin's math book ...

You should submit your code and let it optimized or sthg like that.

infinie, time has been against me recently so I havn't attempted this yet, but looking at it I don't think it the best candidate for optimisation to be honest.

To solve this you really need to use transcendental functions, most probably a cos/sin as well as probably an arccos/sin. These would require so many clock cycles that they'd drown out optimisations of the rest of the solution.

Plus the solution is quite long which makes it a pain to code :grin: .

To solve this you really need to use transcendental functions, most probably a cos/sin as well as probably an arccos/sin. These would require so many clock cycles that they'd drown out optimisations of the rest of the solution.

Plus the solution is quite long which makes it a pain to code :grin: .

you will need:

atan

sin

LOTS of fld fstp

atan

sin

LOTS of fld fstp

InFinie - Like Eoin says, may not be the best canidate -- working on a solution and will post shortly, but has many fpu instructions. These will be optimized but only up to the point where fsqrt and fpatan are required.

A working snippet (does not handle degenerate cases)

.data

m REAL8 5.0

n REAL8 4.0

r REAL8 6.0

q REAL8 2.0

.code

fld m

fmul st(0),st(0)

fld n

fmul st(0),st(0)

fadd

fsqrt ; L = sqrt( m*m+n*n )

fld st(0)

fld r ; r, L

fld q ; q, r, L

fmul st(0),st(0) ; q*q, r, L

fld st(2) ; L, q*q, r, L

fmul st(0),st(0) ; L*L, q*q, r, L

fsubr ; L*L-q*q, r, L

fxch

fld st

fmul st(0),st(0) ; r*r, r, L*L-q*q, L

fxch

fxch st(2)

fadd ; r*r+L*L-q*q, r, L

fxch st(2)

fmul

fld1

fadd st(0),st(0)

fmul ; 2rL, r*r+L*L-q*q

fdiv ; (r*r+L*L-q*q)/(2rL) = cos(u)

farcsin

fldpi

fld1

fadd st(0),st(0)

fdiv

fsubr ; u, L

fxch ; L, u

fld q ; q, L

fld r ; r, q, L

fmul st(0),st(0) ; r*r, q, L

fld st(2) ; L, r*r, q, L

fmul st(0),st(0) ; L*L, r*r, q, L

fsubr ; L*L-r*r, q, L

fxch

fld st

fmul st(0),st(0) ; q*q, q, L*L-r*r, L

fxch

fxch st(2)

fadd ; q*q+L*L-r*r, q, L

fxch st(2)

fmul

fld1

fadd st(0),st(0)

fmul ; 2qL, q*q+L*L-r*r

fdiv ; (q*q+L*L-r*r)/(2qL) = cos(v)

farcsin

fldpi

fld1

fadd st(0),st(0)

fdiv

fsubr ; v, u

fld st(0)

fxch

fsincos

fmul ; sin2v/2, v, u

fxch

fldpi

fmul

fadd st(0),st(0)

fsubr

fld q

fmul st(0),st(0)

fmul ; A1, u

fxch

fld st(0)

fxch

fsincos

fmul ; sin2u/2, u, A1

fxch

fldpi

fmul

fadd st(0),st(0)

fsubr

fld r

fmul st(0),st(0)

fmul ; A2, A1

fadd ; A

` farcsin macro`

; x

fld st ; x, x

fmul st, st ; x * x, x

fld1 ; 1, x * x, x

fsubr ; 1 - x * x, x

fsqrt ; sqrt(1 - x * x), x

fpatan ; atan(x / sqrt(1 - x * x))

endm

You can get the area of intersection by integrating

After substituting x with d/2 and -d/2 ( where d is the length of the chord ), you get

But you have to substract the area of the remaining rectangle so

Therefore the area of intersection is:

**f(x) = sqrt(r^2-x^2)**.After substituting x with d/2 and -d/2 ( where d is the length of the chord ), you get

**r^2*asin( d/ (2*abs(r)) )**

But you have to substract the area of the remaining rectangle so

**r^2*asin( d/ (2*abs(r)) ) - d*sqrt(4*r^2-d^2)/4**

Therefore the area of intersection is:

**r1^2*asin( d/ (2*abs(r1)) ) - d*sqrt(4*r1^2-d^2)/4 + r2^2*asin( d/ (2*abs(r)) ) - d*sqrt(4*r2^2-d^2)/4**

Length of the chord is not given. But you can calculate it. It seems it complicates things. After you've found the intersection points, you can get the answer by integrating but not by integrating your f(x) I suppose. Because it only considers the upper half of the circle. Usage of polar coordinates may be a better candidate.

i.e. take a circle centered at origin: r=k where k is the radius.

Let's define an alpha which the intersection points are on the circle. Better said: at alpha on the circle there is a point, at -alpha there is the other one.

Then we can find the area of one chord by:

t=theta,

a=alpha

which will give us

A1 or A2 in TheoMcCloskey's post :D

i.e. take a circle centered at origin: r=k where k is the radius.

Let's define an alpha which the intersection points are on the circle. Better said: at alpha on the circle there is a point, at -alpha there is the other one.

Then we can find the area of one chord by:

t=theta,

a=alpha

int(-a, a, int(0, k, r dr dt)) - int(-a, a, int(0, k sint, r dr dt))

which will give us

A1 or A2 in TheoMcCloskey's post :D