Can i use a system.drawing.point to store 2 doubles?

Posted on 2006-04-24
Last Modified: 2008-03-03
See code on this link:

Lat longs need doubles.... can i use this code with doubles? It seems point needs int as arguments.



copy of the code:
// Define our two points
Point p1 = new Point(73, 40); // 73 degrees west 40 degrees north (New York City)
Point p2 = new Point(-6, 50); // 6 degrees east and 50 degrees north (Cologne)

double DegToRadFactor = (Math.PI / 180);
double RadiusOfTheEarth = 3959; /// Radius of the earth in miles (can also be 6371 kilometers)

/// Math.Cos just use radiants, instead of degrees, so calculate the rad's
double p1X = p1.X * DegToRadFactor;
double p1Y = p1.Y * DegToRadFactor;
double p2X = p2.X * DegToRadFactor;
double p2Y = p2.Y * DegToRadFactor;
double der = Math.Cos(p1Y) * Math.Cos(p2Y) * Math.Cos(p2X - p1X) + Math.Sin(p1Y) * Math.Sin(p2Y);
/// Calculate Distance
double distance = Math.Acos(der) * RadiusOfTheEarth;

Question by:verintsupport
    LVL 10

    Accepted Solution

    please try the PointF structure

    PointF p1 = new PointF(73.11, 40.2332);

    LVL 48

    Expert Comment

    Cast integer to double. I guess p1Y is p1.Y, so you need:

    double der = Math.Cos((double)p1.Y) * Math.Cos((double)p2.Y) * Math.Cos((double)p2.X - (double)p1.X) + Math.Sin((double)p1.Y) * Math.Sin((double)p2.Y);

    Author Comment

    is there any point structure in 3d?

    (x,y,z) all in double?

    LVL 48

    Expert Comment

    Oops, ignore my post.
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    You can define your own struct...

            private struct Point3D
                public double x;
                public double y;
                public double z;

            private void button1_Click(object sender, EventArgs e)
                Point3D p;
                p.x = 73.11;
                p.y = 40.2332;
                p.z = 115.233;

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now