Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I calculate the area around a given point

Let’s say I have the coordinates 0, 0 as my center point. And I want to calculate an area that extrudes 6 tiles (1 tile being 1 unit) each direction from the center point, essentially building a rectangle that’s 13×13 based on the center point.

This is what I have, but I feel as if that’s not correct.

class Program
{
    static Point AbsPos = new Point(0, 0);
    static Point Rectangle;

    static void Main(string[] args)
    {
       Rectangle = new Point(AbsPos.X * 13, AbsPos.Y * 13);
    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

For a grid of same-shaped tiles, the location of the center of a square has no influence on its area. A 13×13 square has an area of 169 regardless of whether it’s located at 0,0 or 17,22. If your user is going to give you 6 as an input then you simply need to do:

Console.WriteLine(Math.Pow((2 * input) + 1, 2));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading