Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#JavaScript (ES6), 72 bytes

JavaScript (ES6), 72 bytes

Alternate formula suggested by @ceilingcat

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

with(Math)f=(x,y,X,Y,r)=>-(sin(d=2*acos(hypot(x-X,y-Y)/r/2))-d)*r*r*2>>1

Try it online!


#JavaScript (ES7), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 77 bytes

JavaScript (ES7), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r-d*d)**.5>>1

Try it online!

###How?

How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt((2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(r'2 - d2)) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

#JavaScript (ES6), 72 bytes

Alternate formula suggested by @ceilingcat

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

with(Math)f=(x,y,X,Y,r)=>-(sin(d=2*acos(hypot(x-X,y-Y)/r/2))-d)*r*r*2>>1

Try it online!


#JavaScript (ES7), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r-d*d)**.5>>1

Try it online!

###How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt((2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(r'2 - d2)) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

JavaScript (ES6), 72 bytes

Alternate formula suggested by @ceilingcat

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

with(Math)f=(x,y,X,Y,r)=>-(sin(d=2*acos(hypot(x-X,y-Y)/r/2))-d)*r*r*2>>1

Try it online!


JavaScript (ES7), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r-d*d)**.5>>1

Try it online!

How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt((2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(r'2 - d2)) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

added an alternate version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES7ES6), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 7772 bytes

Saved 3 bytes thanks to @NeilAlternate formula suggested by @ceilingcat

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

with(Math)f=(x,y,X,Y,r,d=Math.)=>-(sin(d=2*acos(hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r/2)-d*(r*r)-d*dd)**.5>>1*r*r*2>>1

Try it online!


#JavaScript (ES7), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r-d*d)**.5>>1

Try it online!

###How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt((2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(r'2 - d2)) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

#JavaScript (ES7), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r-d*d)**.5>>1

Try it online!

###How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt((2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(r'2 - d2)) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

#JavaScript (ES6), 72 bytes

Alternate formula suggested by @ceilingcat

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

with(Math)f=(x,y,X,Y,r)=>-(sin(d=2*acos(hypot(x-X,y-Y)/r/2))-d)*r*r*2>>1

Try it online!


#JavaScript (ES7), (削除) 81 (削除ここまで)(削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r-d*d)**.5>>1

Try it online!

###How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt((2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(r'2 - d2)) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

saved 3 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES7), (削除) 81 (削除ここまで) 80(削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,Y-y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r*d*dr*r-d**4d*d)**.5>>1

Try it online! Try it online!

###How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt(d2 * (2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(d2(r'2 - d2))) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

#JavaScript (ES7), (削除) 81 (削除ここまで) 80 bytes

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,Y-y))=>(r*=2)*r*Math.acos(d/r)-(r*r*d*d-d**4)**.5>>1

Try it online!

###How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + sqrt(d2 * (2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + sqrt(d2(r'2 - d2))) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

#JavaScript (ES7), (削除) 81 (削除ここまで) (削除) 80 (削除ここまで) 77 bytes

Saved 3 bytes thanks to @Neil

Takes input as 5 distinct parameters (x0, y0, x1, y1, r).

(x,y,X,Y,r,d=Math.hypot(x-X,y-Y))=>(r*=2)*r*Math.acos(d/r)-d*(r*r-d*d)**.5>>1

Try it online!

###How?

This is based on a generic formula from MathWorld for non-congruent circles:

A = r2.arccos((d2 + r2 - R2) / 2dr) +
 R2.arccos((d2 + R2 - r2) / 2dR) -
 sqrt((-d + r + R)(d + r - R)(d -r + R)(d + r + R)) / 2

where d is the distance between the two centers and r and R are the radii.

With R = r, this is simplified to:

A = 2r2.arccos(d / 2r) + d.sqrt((2r - d) * (2r + d)) / 2

And with r' = 2r:

A = (r'2.arccos(d / r') + d.sqrt(r'2 - d2)) / 2

Note: If d is greater than 2r, Math.acos() will return NaN, which is coerced to 0 when the right-shift is applied. This is the expected result, because d > 2r means that there's no intersection at all.

added the 'How?' section
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
added the 'How?' section
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

AltStyle によって変換されたページ (->オリジナル) /