Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,239 questions

56,142 answers

573 users

How to calculate the Euclidean distance between two points in C#

1 Answer

0 votes
// The Euclidean distance is a measure of the straight-line distance 
// between two points in a 2D or 3D space

using System;

class EuclideanDistance
{
    // Function to calculate Euclidean distance
    static double CalculateEuclideanDistance(double x1, double y1, double x2, double y2) {
        return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
    }

    static void Main()
    {
        double x1 = 3.0, y1 = 4.0;
        double x2 = 5.0, y2 = 9.0;

        double distance = CalculateEuclideanDistance(x1, y1, x2, y2);

        Console.WriteLine($"Euclidean Distance: {distance:F5}");
    }
}



/*
run:

Euclidean Distance: 5.38516

*/

 



answered Oct 12, 2025 by avibootz
edited Oct 13, 2025 by avibootz
...