The Knight's estateCircle packing in a rectangleFinding Exclusive Area in Circle Intersectionsg​o​l​f​ ​a​t​a​n​2Escape a chessboardDraw A Reuleaux Triangle!Find the IntersectionsScore a single dartMagic: The Gathering, Paying for SpellsIs this quadrilateral cyclic?Golf the smallest circle!

You have 3 cakes. Everytime you eat one, there's 17% chance the number of cakes is reset to 3. Find average number of cakes eaten?

Can a Rogue PC teach an NPC to perform Sneak Attack?

Compelling story with the world as a villain

How to prevent clipped screen edges on my TV, HDMI-connected?

Is there any music source code for sound chips?

Examples of topos that are not ordinary spaces

Why do all fields in a QFT transform like *irreducible* representations of some group?

Architectural feasibility of a tiered circular stone keep

Does norwegian.no airline overbook flights?

Why did they avoid parodying Martian Manhunter?

Is there any way to keep a player from killing an NPC?

Immutable builder and updater

Did a flight controller ever answer Flight with a no-go?

If all stars rotate, why was there a theory developed that requires non-rotating stars?

Who was president of the USA?

Why did Khan ask Admiral James T. Kirk about Project Genesis?

What does "set -x" do in a bash script?

How is the idea of "two people having a heated argument" idiomatically expressed in German?

Is gzip atomic?

Are the players on the same team as the DM?

How would you identify when an object in a Lissajous orbit needs station keeping?

Why would an IIS hosted site prompt for AD account credential if accessed through a hostname or IP, but not through servername?

Are modern clipless shoes and pedals that much better than toe clips and straps?

Is “I am getting married with my sister” ambiguous?



The Knight's estate


Circle packing in a rectangleFinding Exclusive Area in Circle Intersectionsg​o​l​f​ ​a​t​a​n​2Escape a chessboardDraw A Reuleaux Triangle!Find the IntersectionsScore a single dartMagic: The Gathering, Paying for SpellsIs this quadrilateral cyclic?Golf the smallest circle!






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3












$begingroup$


And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. However, the strictest of the prohibitions was violated by you - all the warriors saw you fighting without a hat on your head like savages, and their evil spirits could inhabit you. You know that the law of the ancestors tells you to send souls like you to heaven until the evil that could take root in them escapes. But it is in my will to spare you, for I see that you are strong enough not to allow this evil to penetrate your thoughts and soul. You must make a vow for three months and not leave your land for three days and every day three hours after sunset to pray good spirits for protection. Things rush me, and I can not take you to the castle. Therefore, I will give you the way from this place to the castle. Now go and come back after the deadline. - as it is written in the Green Book of Years.



In addition, it is known from the Green Book of Years that the lands with which the castle was granted were in the shape of a circle. The king was very wise and, in order to avoid unnecessary proceedings regarding the right to land, always granted only areas of land on the map that have a convex shape.



Recently, historians have had information about where the castle was located and where this historical conversation took place. They want to know how much land did the Knight get on the assumption that the road to the castle was perfectly straight.



Explanation



The following figure shows in light gray the territory originally granted to the knight, and in dark gray, the one that came to him as a result of the king giving him the way.





Input



The first line of the input contains two real numbers xk and yk - the coordinates of the place where the dialogue took place. The second line contains three decimals: xc, yc and rc - the coordinates of the castle and the radius of the circle that bounds the land granted with it.



Output



Print one real number - the area of ​​the land obtained by the Knight, with an accuracy of at least three characters after the decimal point.



Tests



Input    Output



2 5       5.69646

2 1 1




3 9       80.71304

2 3 5




1 3       1.5708

1 2 1





Note: A triangle may not include the entire semicircle if it is too close to the center, as in the test I have given.










share|improve this question











$endgroup$









  • 4




    $begingroup$
    Hi there! Please consider using The Sandbox for your challenges. I've read this several times and I'm not sure what area we're supposed to find. The dark grey? The light grey? The sum of those regions?
    $endgroup$
    – Giuseppe
    11 hours ago






  • 5




    $begingroup$
    Please also avoid excessively long backstories. In this case, because the challenge refers back to the backstory, it actually hinders your challenge. :-(
    $endgroup$
    – Giuseppe
    11 hours ago










  • $begingroup$
    @Giuseppe The sum of those regions.
    $endgroup$
    – Ver Nick
    11 hours ago







  • 1




    $begingroup$
    Can you please provide examples with a radius unequal to 1?
    $endgroup$
    – Jitse
    10 hours ago






  • 4




    $begingroup$
    Why is the outcome of the third test case not 3.141?
    $endgroup$
    – Joel
    5 hours ago

















3












$begingroup$


And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. However, the strictest of the prohibitions was violated by you - all the warriors saw you fighting without a hat on your head like savages, and their evil spirits could inhabit you. You know that the law of the ancestors tells you to send souls like you to heaven until the evil that could take root in them escapes. But it is in my will to spare you, for I see that you are strong enough not to allow this evil to penetrate your thoughts and soul. You must make a vow for three months and not leave your land for three days and every day three hours after sunset to pray good spirits for protection. Things rush me, and I can not take you to the castle. Therefore, I will give you the way from this place to the castle. Now go and come back after the deadline. - as it is written in the Green Book of Years.



In addition, it is known from the Green Book of Years that the lands with which the castle was granted were in the shape of a circle. The king was very wise and, in order to avoid unnecessary proceedings regarding the right to land, always granted only areas of land on the map that have a convex shape.



Recently, historians have had information about where the castle was located and where this historical conversation took place. They want to know how much land did the Knight get on the assumption that the road to the castle was perfectly straight.



Explanation



The following figure shows in light gray the territory originally granted to the knight, and in dark gray, the one that came to him as a result of the king giving him the way.





Input



The first line of the input contains two real numbers xk and yk - the coordinates of the place where the dialogue took place. The second line contains three decimals: xc, yc and rc - the coordinates of the castle and the radius of the circle that bounds the land granted with it.



Output



Print one real number - the area of ​​the land obtained by the Knight, with an accuracy of at least three characters after the decimal point.



Tests



Input    Output



2 5       5.69646

2 1 1




3 9       80.71304

2 3 5




1 3       1.5708

1 2 1





Note: A triangle may not include the entire semicircle if it is too close to the center, as in the test I have given.










share|improve this question











$endgroup$









  • 4




    $begingroup$
    Hi there! Please consider using The Sandbox for your challenges. I've read this several times and I'm not sure what area we're supposed to find. The dark grey? The light grey? The sum of those regions?
    $endgroup$
    – Giuseppe
    11 hours ago






  • 5




    $begingroup$
    Please also avoid excessively long backstories. In this case, because the challenge refers back to the backstory, it actually hinders your challenge. :-(
    $endgroup$
    – Giuseppe
    11 hours ago










  • $begingroup$
    @Giuseppe The sum of those regions.
    $endgroup$
    – Ver Nick
    11 hours ago







  • 1




    $begingroup$
    Can you please provide examples with a radius unequal to 1?
    $endgroup$
    – Jitse
    10 hours ago






  • 4




    $begingroup$
    Why is the outcome of the third test case not 3.141?
    $endgroup$
    – Joel
    5 hours ago













3












3








3


1



$begingroup$


And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. However, the strictest of the prohibitions was violated by you - all the warriors saw you fighting without a hat on your head like savages, and their evil spirits could inhabit you. You know that the law of the ancestors tells you to send souls like you to heaven until the evil that could take root in them escapes. But it is in my will to spare you, for I see that you are strong enough not to allow this evil to penetrate your thoughts and soul. You must make a vow for three months and not leave your land for three days and every day three hours after sunset to pray good spirits for protection. Things rush me, and I can not take you to the castle. Therefore, I will give you the way from this place to the castle. Now go and come back after the deadline. - as it is written in the Green Book of Years.



In addition, it is known from the Green Book of Years that the lands with which the castle was granted were in the shape of a circle. The king was very wise and, in order to avoid unnecessary proceedings regarding the right to land, always granted only areas of land on the map that have a convex shape.



Recently, historians have had information about where the castle was located and where this historical conversation took place. They want to know how much land did the Knight get on the assumption that the road to the castle was perfectly straight.



Explanation



The following figure shows in light gray the territory originally granted to the knight, and in dark gray, the one that came to him as a result of the king giving him the way.





Input



The first line of the input contains two real numbers xk and yk - the coordinates of the place where the dialogue took place. The second line contains three decimals: xc, yc and rc - the coordinates of the castle and the radius of the circle that bounds the land granted with it.



Output



Print one real number - the area of ​​the land obtained by the Knight, with an accuracy of at least three characters after the decimal point.



Tests



Input    Output



2 5       5.69646

2 1 1




3 9       80.71304

2 3 5




1 3       1.5708

1 2 1





Note: A triangle may not include the entire semicircle if it is too close to the center, as in the test I have given.










share|improve this question











$endgroup$




And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. However, the strictest of the prohibitions was violated by you - all the warriors saw you fighting without a hat on your head like savages, and their evil spirits could inhabit you. You know that the law of the ancestors tells you to send souls like you to heaven until the evil that could take root in them escapes. But it is in my will to spare you, for I see that you are strong enough not to allow this evil to penetrate your thoughts and soul. You must make a vow for three months and not leave your land for three days and every day three hours after sunset to pray good spirits for protection. Things rush me, and I can not take you to the castle. Therefore, I will give you the way from this place to the castle. Now go and come back after the deadline. - as it is written in the Green Book of Years.



In addition, it is known from the Green Book of Years that the lands with which the castle was granted were in the shape of a circle. The king was very wise and, in order to avoid unnecessary proceedings regarding the right to land, always granted only areas of land on the map that have a convex shape.



Recently, historians have had information about where the castle was located and where this historical conversation took place. They want to know how much land did the Knight get on the assumption that the road to the castle was perfectly straight.



Explanation



The following figure shows in light gray the territory originally granted to the knight, and in dark gray, the one that came to him as a result of the king giving him the way.





Input



The first line of the input contains two real numbers xk and yk - the coordinates of the place where the dialogue took place. The second line contains three decimals: xc, yc and rc - the coordinates of the castle and the radius of the circle that bounds the land granted with it.



Output



Print one real number - the area of ​​the land obtained by the Knight, with an accuracy of at least three characters after the decimal point.



Tests



Input    Output



2 5       5.69646

2 1 1




3 9       80.71304

2 3 5




1 3       1.5708

1 2 1





Note: A triangle may not include the entire semicircle if it is too close to the center, as in the test I have given.







code-golf geometry






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 hours ago







Ver Nick

















asked 11 hours ago









Ver NickVer Nick

2231 silver badge7 bronze badges




2231 silver badge7 bronze badges










  • 4




    $begingroup$
    Hi there! Please consider using The Sandbox for your challenges. I've read this several times and I'm not sure what area we're supposed to find. The dark grey? The light grey? The sum of those regions?
    $endgroup$
    – Giuseppe
    11 hours ago






  • 5




    $begingroup$
    Please also avoid excessively long backstories. In this case, because the challenge refers back to the backstory, it actually hinders your challenge. :-(
    $endgroup$
    – Giuseppe
    11 hours ago










  • $begingroup$
    @Giuseppe The sum of those regions.
    $endgroup$
    – Ver Nick
    11 hours ago







  • 1




    $begingroup$
    Can you please provide examples with a radius unequal to 1?
    $endgroup$
    – Jitse
    10 hours ago






  • 4




    $begingroup$
    Why is the outcome of the third test case not 3.141?
    $endgroup$
    – Joel
    5 hours ago












  • 4




    $begingroup$
    Hi there! Please consider using The Sandbox for your challenges. I've read this several times and I'm not sure what area we're supposed to find. The dark grey? The light grey? The sum of those regions?
    $endgroup$
    – Giuseppe
    11 hours ago






  • 5




    $begingroup$
    Please also avoid excessively long backstories. In this case, because the challenge refers back to the backstory, it actually hinders your challenge. :-(
    $endgroup$
    – Giuseppe
    11 hours ago










  • $begingroup$
    @Giuseppe The sum of those regions.
    $endgroup$
    – Ver Nick
    11 hours ago







  • 1




    $begingroup$
    Can you please provide examples with a radius unequal to 1?
    $endgroup$
    – Jitse
    10 hours ago






  • 4




    $begingroup$
    Why is the outcome of the third test case not 3.141?
    $endgroup$
    – Joel
    5 hours ago







4




4




$begingroup$
Hi there! Please consider using The Sandbox for your challenges. I've read this several times and I'm not sure what area we're supposed to find. The dark grey? The light grey? The sum of those regions?
$endgroup$
– Giuseppe
11 hours ago




$begingroup$
Hi there! Please consider using The Sandbox for your challenges. I've read this several times and I'm not sure what area we're supposed to find. The dark grey? The light grey? The sum of those regions?
$endgroup$
– Giuseppe
11 hours ago




5




5




$begingroup$
Please also avoid excessively long backstories. In this case, because the challenge refers back to the backstory, it actually hinders your challenge. :-(
$endgroup$
– Giuseppe
11 hours ago




$begingroup$
Please also avoid excessively long backstories. In this case, because the challenge refers back to the backstory, it actually hinders your challenge. :-(
$endgroup$
– Giuseppe
11 hours ago












$begingroup$
@Giuseppe The sum of those regions.
$endgroup$
– Ver Nick
11 hours ago





$begingroup$
@Giuseppe The sum of those regions.
$endgroup$
– Ver Nick
11 hours ago





1




1




$begingroup$
Can you please provide examples with a radius unequal to 1?
$endgroup$
– Jitse
10 hours ago




$begingroup$
Can you please provide examples with a radius unequal to 1?
$endgroup$
– Jitse
10 hours ago




4




4




$begingroup$
Why is the outcome of the third test case not 3.141?
$endgroup$
– Joel
5 hours ago




$begingroup$
Why is the outcome of the third test case not 3.141?
$endgroup$
– Joel
5 hours ago










5 Answers
5






active

oldest

votes


















3













$begingroup$

JavaScript (ES7), 76 bytes



Port of Jitse's answer.





with(Math)f=(X,Y,x,y,r,h=hypot(X-x,Y-y))=>r*(r*(PI-acos(r/h))+(h*h-r*r)**.5)


Try it online!






share|improve this answer











$endgroup$














  • $begingroup$
    I borrowed your argument names for clarity
    $endgroup$
    – Jitse
    10 hours ago






  • 5




    $begingroup$
    @Jitse Sounds fair enough since I borrowed your entire logic. :p
    $endgroup$
    – Arnauld
    10 hours ago










  • $begingroup$
    Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.
    $endgroup$
    – Jitse
    10 hours ago










  • $begingroup$
    @Jitse Thanks. :)
    $endgroup$
    – Arnauld
    10 hours ago










  • $begingroup$
    It's been a while but +1 for with - always +1 for with!
    $endgroup$
    – Shaggy
    51 mins ago


















3













$begingroup$


Python 3, 112 bytes





from math import*
def f(X,Y,x,y,r):d=(X-x)**2+(Y-y)**2;return(r>d)*pi*r*r or(pi-acos(r/d**.5))*r*r+(d-r*r)**.5*r


Try it online!



-3 bytes thanks to Arnauld



-4 bytes thanks to squid



Explanation



First, we calculate the traveled distance between both coordinates using the Pythagorean theorem. Let's call it d.



Then, we construct a rectangular triangle between coordinate 1, coordinate 2 and the point on the circle where it meets with the straight line. Using the Pythaogrean theorem again, the area of this triangle is given by $$frac12timessqrtd^2-r^2times r$$
where d is the distance between the coordinates and r is the radius of the circle. Since we have two of those triangles, this area is resembled in the code by (d*d-r*r)**.5*r



Next, we need to calculate the remaining area of the circle. A circle's area is given by $$ a = pitimes r^2$$
However, part of the circle is already taken into account. The angular fraction of the circle that is already described by the triangles is given as $$cos^-1(r/d)$$
so that the remaining area in the circle can be described by (pi-acos(r/d))*r*r.



And then some code juggle to make it as short as possible. For example: the square root operation to calculate d is applied when d is actually used instead of beforehand.



Except...



when the traveled distance lies within the circle. Then just return the circle area.






share|improve this answer











$endgroup$














  • $begingroup$
    I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.
    $endgroup$
    – Ver Nick
    10 hours ago











  • $begingroup$
    @VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.
    $endgroup$
    – Jitse
    10 hours ago











  • $begingroup$
    BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)
    $endgroup$
    – Ver Nick
    8 hours ago










  • $begingroup$
    Shouldn't it be r*r>d rather than r>d?
    $endgroup$
    – Joel
    6 hours ago


















1













$begingroup$


Python 3.8 (pre-release), 93 bytes





from math import*
f=lambda X,Y,x,y,r:((t:=max(hypot(X-x,Y-y)**2/r/r-1,0)**.5)-atan(t)+pi)*r*r


Try it online!



This solution is based on a bit more math manipulation of the formula. Let $theta$ be the size of common angle of each triangle and its corresponding sector. The area of each triangle equals to $frac12times rtanthetatimes r$ and the area of the common sector of the triangles and the circle equals to $thetatimes rtimes r$. Hence, the total area $$S=tanthetacdot r^2 +pi r^2-theta r^2=(pi+tantheta-theta)r^2$$



We define $t$ to be $$t=tantheta=fracsqrtd^2-r^2r=sqrtfracd^2r^2-1$$
Here, $d$ is the distance between the two given coordinate pairs. Then we have $$S=(pi+t-arctant)r^2$$






share|improve this answer








New contributor



Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





$endgroup$






















    1













    $begingroup$


    Wolfram Language (Mathematica), 51 bytes



    Area@ConvexHullMesh[CirclePoints[##2,7!]~Append~#]&


    Try it online!



     CirclePoints[##2,7!] (* generate 5040 points on the perimeter of the circle *)
    ~Append~# (* append the point at the end of the way, *)
    Area@ConvexHullMesh[ ]& (* and find the area of the convex hull of those points *)





    share|improve this answer











    $endgroup$






















      1













      $begingroup$


      Jelly, 33 bytes



      ½÷@ÆAØP_ײ}
      I²SḢ_²}½×ʋ+çɗṛ²×ØPʋ>?


      Try it online!



      Port of @jitse’s Python answer so be sure to upvote that one! A full program taking as its arguments [[xk, xc], [yk, yx]] and r.






      share|improve this answer









      $endgroup$

















        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "200"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f190733%2fthe-knights-estate%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3













        $begingroup$

        JavaScript (ES7), 76 bytes



        Port of Jitse's answer.





        with(Math)f=(X,Y,x,y,r,h=hypot(X-x,Y-y))=>r*(r*(PI-acos(r/h))+(h*h-r*r)**.5)


        Try it online!






        share|improve this answer











        $endgroup$














        • $begingroup$
          I borrowed your argument names for clarity
          $endgroup$
          – Jitse
          10 hours ago






        • 5




          $begingroup$
          @Jitse Sounds fair enough since I borrowed your entire logic. :p
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.
          $endgroup$
          – Jitse
          10 hours ago










        • $begingroup$
          @Jitse Thanks. :)
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          It's been a while but +1 for with - always +1 for with!
          $endgroup$
          – Shaggy
          51 mins ago















        3













        $begingroup$

        JavaScript (ES7), 76 bytes



        Port of Jitse's answer.





        with(Math)f=(X,Y,x,y,r,h=hypot(X-x,Y-y))=>r*(r*(PI-acos(r/h))+(h*h-r*r)**.5)


        Try it online!






        share|improve this answer











        $endgroup$














        • $begingroup$
          I borrowed your argument names for clarity
          $endgroup$
          – Jitse
          10 hours ago






        • 5




          $begingroup$
          @Jitse Sounds fair enough since I borrowed your entire logic. :p
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.
          $endgroup$
          – Jitse
          10 hours ago










        • $begingroup$
          @Jitse Thanks. :)
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          It's been a while but +1 for with - always +1 for with!
          $endgroup$
          – Shaggy
          51 mins ago













        3














        3










        3







        $begingroup$

        JavaScript (ES7), 76 bytes



        Port of Jitse's answer.





        with(Math)f=(X,Y,x,y,r,h=hypot(X-x,Y-y))=>r*(r*(PI-acos(r/h))+(h*h-r*r)**.5)


        Try it online!






        share|improve this answer











        $endgroup$



        JavaScript (ES7), 76 bytes



        Port of Jitse's answer.





        with(Math)f=(X,Y,x,y,r,h=hypot(X-x,Y-y))=>r*(r*(PI-acos(r/h))+(h*h-r*r)**.5)


        Try it online!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 10 hours ago

























        answered 10 hours ago









        ArnauldArnauld

        90.8k7 gold badges106 silver badges371 bronze badges




        90.8k7 gold badges106 silver badges371 bronze badges














        • $begingroup$
          I borrowed your argument names for clarity
          $endgroup$
          – Jitse
          10 hours ago






        • 5




          $begingroup$
          @Jitse Sounds fair enough since I borrowed your entire logic. :p
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.
          $endgroup$
          – Jitse
          10 hours ago










        • $begingroup$
          @Jitse Thanks. :)
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          It's been a while but +1 for with - always +1 for with!
          $endgroup$
          – Shaggy
          51 mins ago
















        • $begingroup$
          I borrowed your argument names for clarity
          $endgroup$
          – Jitse
          10 hours ago






        • 5




          $begingroup$
          @Jitse Sounds fair enough since I borrowed your entire logic. :p
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.
          $endgroup$
          – Jitse
          10 hours ago










        • $begingroup$
          @Jitse Thanks. :)
          $endgroup$
          – Arnauld
          10 hours ago










        • $begingroup$
          It's been a while but +1 for with - always +1 for with!
          $endgroup$
          – Shaggy
          51 mins ago















        $begingroup$
        I borrowed your argument names for clarity
        $endgroup$
        – Jitse
        10 hours ago




        $begingroup$
        I borrowed your argument names for clarity
        $endgroup$
        – Jitse
        10 hours ago




        5




        5




        $begingroup$
        @Jitse Sounds fair enough since I borrowed your entire logic. :p
        $endgroup$
        – Arnauld
        10 hours ago




        $begingroup$
        @Jitse Sounds fair enough since I borrowed your entire logic. :p
        $endgroup$
        – Arnauld
        10 hours ago












        $begingroup$
        Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.
        $endgroup$
        – Jitse
        10 hours ago




        $begingroup$
        Friendly reminder that I made a mistake in the calcualtion of the triangle's area. It worked because the radius in the example is 1.
        $endgroup$
        – Jitse
        10 hours ago












        $begingroup$
        @Jitse Thanks. :)
        $endgroup$
        – Arnauld
        10 hours ago




        $begingroup$
        @Jitse Thanks. :)
        $endgroup$
        – Arnauld
        10 hours ago












        $begingroup$
        It's been a while but +1 for with - always +1 for with!
        $endgroup$
        – Shaggy
        51 mins ago




        $begingroup$
        It's been a while but +1 for with - always +1 for with!
        $endgroup$
        – Shaggy
        51 mins ago













        3













        $begingroup$


        Python 3, 112 bytes





        from math import*
        def f(X,Y,x,y,r):d=(X-x)**2+(Y-y)**2;return(r>d)*pi*r*r or(pi-acos(r/d**.5))*r*r+(d-r*r)**.5*r


        Try it online!



        -3 bytes thanks to Arnauld



        -4 bytes thanks to squid



        Explanation



        First, we calculate the traveled distance between both coordinates using the Pythagorean theorem. Let's call it d.



        Then, we construct a rectangular triangle between coordinate 1, coordinate 2 and the point on the circle where it meets with the straight line. Using the Pythaogrean theorem again, the area of this triangle is given by $$frac12timessqrtd^2-r^2times r$$
        where d is the distance between the coordinates and r is the radius of the circle. Since we have two of those triangles, this area is resembled in the code by (d*d-r*r)**.5*r



        Next, we need to calculate the remaining area of the circle. A circle's area is given by $$ a = pitimes r^2$$
        However, part of the circle is already taken into account. The angular fraction of the circle that is already described by the triangles is given as $$cos^-1(r/d)$$
        so that the remaining area in the circle can be described by (pi-acos(r/d))*r*r.



        And then some code juggle to make it as short as possible. For example: the square root operation to calculate d is applied when d is actually used instead of beforehand.



        Except...



        when the traveled distance lies within the circle. Then just return the circle area.






        share|improve this answer











        $endgroup$














        • $begingroup$
          I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.
          $endgroup$
          – Ver Nick
          10 hours ago











        • $begingroup$
          @VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.
          $endgroup$
          – Jitse
          10 hours ago











        • $begingroup$
          BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)
          $endgroup$
          – Ver Nick
          8 hours ago










        • $begingroup$
          Shouldn't it be r*r>d rather than r>d?
          $endgroup$
          – Joel
          6 hours ago















        3













        $begingroup$


        Python 3, 112 bytes





        from math import*
        def f(X,Y,x,y,r):d=(X-x)**2+(Y-y)**2;return(r>d)*pi*r*r or(pi-acos(r/d**.5))*r*r+(d-r*r)**.5*r


        Try it online!



        -3 bytes thanks to Arnauld



        -4 bytes thanks to squid



        Explanation



        First, we calculate the traveled distance between both coordinates using the Pythagorean theorem. Let's call it d.



        Then, we construct a rectangular triangle between coordinate 1, coordinate 2 and the point on the circle where it meets with the straight line. Using the Pythaogrean theorem again, the area of this triangle is given by $$frac12timessqrtd^2-r^2times r$$
        where d is the distance between the coordinates and r is the radius of the circle. Since we have two of those triangles, this area is resembled in the code by (d*d-r*r)**.5*r



        Next, we need to calculate the remaining area of the circle. A circle's area is given by $$ a = pitimes r^2$$
        However, part of the circle is already taken into account. The angular fraction of the circle that is already described by the triangles is given as $$cos^-1(r/d)$$
        so that the remaining area in the circle can be described by (pi-acos(r/d))*r*r.



        And then some code juggle to make it as short as possible. For example: the square root operation to calculate d is applied when d is actually used instead of beforehand.



        Except...



        when the traveled distance lies within the circle. Then just return the circle area.






        share|improve this answer











        $endgroup$














        • $begingroup$
          I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.
          $endgroup$
          – Ver Nick
          10 hours ago











        • $begingroup$
          @VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.
          $endgroup$
          – Jitse
          10 hours ago











        • $begingroup$
          BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)
          $endgroup$
          – Ver Nick
          8 hours ago










        • $begingroup$
          Shouldn't it be r*r>d rather than r>d?
          $endgroup$
          – Joel
          6 hours ago













        3














        3










        3







        $begingroup$


        Python 3, 112 bytes





        from math import*
        def f(X,Y,x,y,r):d=(X-x)**2+(Y-y)**2;return(r>d)*pi*r*r or(pi-acos(r/d**.5))*r*r+(d-r*r)**.5*r


        Try it online!



        -3 bytes thanks to Arnauld



        -4 bytes thanks to squid



        Explanation



        First, we calculate the traveled distance between both coordinates using the Pythagorean theorem. Let's call it d.



        Then, we construct a rectangular triangle between coordinate 1, coordinate 2 and the point on the circle where it meets with the straight line. Using the Pythaogrean theorem again, the area of this triangle is given by $$frac12timessqrtd^2-r^2times r$$
        where d is the distance between the coordinates and r is the radius of the circle. Since we have two of those triangles, this area is resembled in the code by (d*d-r*r)**.5*r



        Next, we need to calculate the remaining area of the circle. A circle's area is given by $$ a = pitimes r^2$$
        However, part of the circle is already taken into account. The angular fraction of the circle that is already described by the triangles is given as $$cos^-1(r/d)$$
        so that the remaining area in the circle can be described by (pi-acos(r/d))*r*r.



        And then some code juggle to make it as short as possible. For example: the square root operation to calculate d is applied when d is actually used instead of beforehand.



        Except...



        when the traveled distance lies within the circle. Then just return the circle area.






        share|improve this answer











        $endgroup$




        Python 3, 112 bytes





        from math import*
        def f(X,Y,x,y,r):d=(X-x)**2+(Y-y)**2;return(r>d)*pi*r*r or(pi-acos(r/d**.5))*r*r+(d-r*r)**.5*r


        Try it online!



        -3 bytes thanks to Arnauld



        -4 bytes thanks to squid



        Explanation



        First, we calculate the traveled distance between both coordinates using the Pythagorean theorem. Let's call it d.



        Then, we construct a rectangular triangle between coordinate 1, coordinate 2 and the point on the circle where it meets with the straight line. Using the Pythaogrean theorem again, the area of this triangle is given by $$frac12timessqrtd^2-r^2times r$$
        where d is the distance between the coordinates and r is the radius of the circle. Since we have two of those triangles, this area is resembled in the code by (d*d-r*r)**.5*r



        Next, we need to calculate the remaining area of the circle. A circle's area is given by $$ a = pitimes r^2$$
        However, part of the circle is already taken into account. The angular fraction of the circle that is already described by the triangles is given as $$cos^-1(r/d)$$
        so that the remaining area in the circle can be described by (pi-acos(r/d))*r*r.



        And then some code juggle to make it as short as possible. For example: the square root operation to calculate d is applied when d is actually used instead of beforehand.



        Except...



        when the traveled distance lies within the circle. Then just return the circle area.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 9 hours ago

























        answered 11 hours ago









        JitseJitse

        1,2843 silver badges19 bronze badges




        1,2843 silver badges19 bronze badges














        • $begingroup$
          I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.
          $endgroup$
          – Ver Nick
          10 hours ago











        • $begingroup$
          @VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.
          $endgroup$
          – Jitse
          10 hours ago











        • $begingroup$
          BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)
          $endgroup$
          – Ver Nick
          8 hours ago










        • $begingroup$
          Shouldn't it be r*r>d rather than r>d?
          $endgroup$
          – Joel
          6 hours ago
















        • $begingroup$
          I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.
          $endgroup$
          – Ver Nick
          10 hours ago











        • $begingroup$
          @VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.
          $endgroup$
          – Jitse
          10 hours ago











        • $begingroup$
          BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)
          $endgroup$
          – Ver Nick
          8 hours ago










        • $begingroup$
          Shouldn't it be r*r>d rather than r>d?
          $endgroup$
          – Joel
          6 hours ago















        $begingroup$
        I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.
        $endgroup$
        – Ver Nick
        10 hours ago





        $begingroup$
        I think you forgot the case, when X-x and Y-y are 0. In this case, there is division by zero.
        $endgroup$
        – Ver Nick
        10 hours ago













        $begingroup$
        @VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.
        $endgroup$
        – Jitse
        10 hours ago





        $begingroup$
        @VerNick Ah yes, you're right. It fails if the traveled distance lies within the circle. Fixed now.
        $endgroup$
        – Jitse
        10 hours ago













        $begingroup$
        BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)
        $endgroup$
        – Ver Nick
        8 hours ago




        $begingroup$
        BTW, a very good explanation, might be useful for those code golfers, that are not very good with geometry ;-)
        $endgroup$
        – Ver Nick
        8 hours ago












        $begingroup$
        Shouldn't it be r*r>d rather than r>d?
        $endgroup$
        – Joel
        6 hours ago




        $begingroup$
        Shouldn't it be r*r>d rather than r>d?
        $endgroup$
        – Joel
        6 hours ago











        1













        $begingroup$


        Python 3.8 (pre-release), 93 bytes





        from math import*
        f=lambda X,Y,x,y,r:((t:=max(hypot(X-x,Y-y)**2/r/r-1,0)**.5)-atan(t)+pi)*r*r


        Try it online!



        This solution is based on a bit more math manipulation of the formula. Let $theta$ be the size of common angle of each triangle and its corresponding sector. The area of each triangle equals to $frac12times rtanthetatimes r$ and the area of the common sector of the triangles and the circle equals to $thetatimes rtimes r$. Hence, the total area $$S=tanthetacdot r^2 +pi r^2-theta r^2=(pi+tantheta-theta)r^2$$



        We define $t$ to be $$t=tantheta=fracsqrtd^2-r^2r=sqrtfracd^2r^2-1$$
        Here, $d$ is the distance between the two given coordinate pairs. Then we have $$S=(pi+t-arctant)r^2$$






        share|improve this answer








        New contributor



        Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        $endgroup$



















          1













          $begingroup$


          Python 3.8 (pre-release), 93 bytes





          from math import*
          f=lambda X,Y,x,y,r:((t:=max(hypot(X-x,Y-y)**2/r/r-1,0)**.5)-atan(t)+pi)*r*r


          Try it online!



          This solution is based on a bit more math manipulation of the formula. Let $theta$ be the size of common angle of each triangle and its corresponding sector. The area of each triangle equals to $frac12times rtanthetatimes r$ and the area of the common sector of the triangles and the circle equals to $thetatimes rtimes r$. Hence, the total area $$S=tanthetacdot r^2 +pi r^2-theta r^2=(pi+tantheta-theta)r^2$$



          We define $t$ to be $$t=tantheta=fracsqrtd^2-r^2r=sqrtfracd^2r^2-1$$
          Here, $d$ is the distance between the two given coordinate pairs. Then we have $$S=(pi+t-arctant)r^2$$






          share|improve this answer








          New contributor



          Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          $endgroup$

















            1














            1










            1







            $begingroup$


            Python 3.8 (pre-release), 93 bytes





            from math import*
            f=lambda X,Y,x,y,r:((t:=max(hypot(X-x,Y-y)**2/r/r-1,0)**.5)-atan(t)+pi)*r*r


            Try it online!



            This solution is based on a bit more math manipulation of the formula. Let $theta$ be the size of common angle of each triangle and its corresponding sector. The area of each triangle equals to $frac12times rtanthetatimes r$ and the area of the common sector of the triangles and the circle equals to $thetatimes rtimes r$. Hence, the total area $$S=tanthetacdot r^2 +pi r^2-theta r^2=(pi+tantheta-theta)r^2$$



            We define $t$ to be $$t=tantheta=fracsqrtd^2-r^2r=sqrtfracd^2r^2-1$$
            Here, $d$ is the distance between the two given coordinate pairs. Then we have $$S=(pi+t-arctant)r^2$$






            share|improve this answer








            New contributor



            Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            $endgroup$




            Python 3.8 (pre-release), 93 bytes





            from math import*
            f=lambda X,Y,x,y,r:((t:=max(hypot(X-x,Y-y)**2/r/r-1,0)**.5)-atan(t)+pi)*r*r


            Try it online!



            This solution is based on a bit more math manipulation of the formula. Let $theta$ be the size of common angle of each triangle and its corresponding sector. The area of each triangle equals to $frac12times rtanthetatimes r$ and the area of the common sector of the triangles and the circle equals to $thetatimes rtimes r$. Hence, the total area $$S=tanthetacdot r^2 +pi r^2-theta r^2=(pi+tantheta-theta)r^2$$



            We define $t$ to be $$t=tantheta=fracsqrtd^2-r^2r=sqrtfracd^2r^2-1$$
            Here, $d$ is the distance between the two given coordinate pairs. Then we have $$S=(pi+t-arctant)r^2$$







            share|improve this answer








            New contributor



            Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.








            share|improve this answer



            share|improve this answer






            New contributor



            Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.








            answered 5 hours ago









            JoelJoel

            1013 bronze badges




            1013 bronze badges




            New contributor



            Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




            New contributor




            Joel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


























                1













                $begingroup$


                Wolfram Language (Mathematica), 51 bytes



                Area@ConvexHullMesh[CirclePoints[##2,7!]~Append~#]&


                Try it online!



                 CirclePoints[##2,7!] (* generate 5040 points on the perimeter of the circle *)
                ~Append~# (* append the point at the end of the way, *)
                Area@ConvexHullMesh[ ]& (* and find the area of the convex hull of those points *)





                share|improve this answer











                $endgroup$



















                  1













                  $begingroup$


                  Wolfram Language (Mathematica), 51 bytes



                  Area@ConvexHullMesh[CirclePoints[##2,7!]~Append~#]&


                  Try it online!



                   CirclePoints[##2,7!] (* generate 5040 points on the perimeter of the circle *)
                  ~Append~# (* append the point at the end of the way, *)
                  Area@ConvexHullMesh[ ]& (* and find the area of the convex hull of those points *)





                  share|improve this answer











                  $endgroup$

















                    1














                    1










                    1







                    $begingroup$


                    Wolfram Language (Mathematica), 51 bytes



                    Area@ConvexHullMesh[CirclePoints[##2,7!]~Append~#]&


                    Try it online!



                     CirclePoints[##2,7!] (* generate 5040 points on the perimeter of the circle *)
                    ~Append~# (* append the point at the end of the way, *)
                    Area@ConvexHullMesh[ ]& (* and find the area of the convex hull of those points *)





                    share|improve this answer











                    $endgroup$




                    Wolfram Language (Mathematica), 51 bytes



                    Area@ConvexHullMesh[CirclePoints[##2,7!]~Append~#]&


                    Try it online!



                     CirclePoints[##2,7!] (* generate 5040 points on the perimeter of the circle *)
                    ~Append~# (* append the point at the end of the way, *)
                    Area@ConvexHullMesh[ ]& (* and find the area of the convex hull of those points *)






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 4 hours ago

























                    answered 4 hours ago









                    attinatattinat

                    2,1272 silver badges10 bronze badges




                    2,1272 silver badges10 bronze badges
























                        1













                        $begingroup$


                        Jelly, 33 bytes



                        ½÷@ÆAØP_ײ}
                        I²SḢ_²}½×ʋ+çɗṛ²×ØPʋ>?


                        Try it online!



                        Port of @jitse’s Python answer so be sure to upvote that one! A full program taking as its arguments [[xk, xc], [yk, yx]] and r.






                        share|improve this answer









                        $endgroup$



















                          1













                          $begingroup$


                          Jelly, 33 bytes



                          ½÷@ÆAØP_ײ}
                          I²SḢ_²}½×ʋ+çɗṛ²×ØPʋ>?


                          Try it online!



                          Port of @jitse’s Python answer so be sure to upvote that one! A full program taking as its arguments [[xk, xc], [yk, yx]] and r.






                          share|improve this answer









                          $endgroup$

















                            1














                            1










                            1







                            $begingroup$


                            Jelly, 33 bytes



                            ½÷@ÆAØP_ײ}
                            I²SḢ_²}½×ʋ+çɗṛ²×ØPʋ>?


                            Try it online!



                            Port of @jitse’s Python answer so be sure to upvote that one! A full program taking as its arguments [[xk, xc], [yk, yx]] and r.






                            share|improve this answer









                            $endgroup$




                            Jelly, 33 bytes



                            ½÷@ÆAØP_ײ}
                            I²SḢ_²}½×ʋ+çɗṛ²×ØPʋ>?


                            Try it online!



                            Port of @jitse’s Python answer so be sure to upvote that one! A full program taking as its arguments [[xk, xc], [yk, yx]] and r.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 2 hours ago









                            Nick KennedyNick Kennedy

                            6,0471 gold badge9 silver badges15 bronze badges




                            6,0471 gold badge9 silver badges15 bronze badges






























                                draft saved

                                draft discarded
















































                                If this is an answer to a challenge…



                                • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                  Explanations of your answer make it more interesting to read and are very much encouraged.


                                • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                More generally…



                                • …Please make sure to answer the question and provide sufficient detail.


                                • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f190733%2fthe-knights-estate%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單