Calculate the distance between these two 3D points - CSharp System

CSharp examples for System:Math Geometry

Description

Calculate the distance between these two 3D points

Demo Code


using Microsoft.Kinect;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from   www .j  a  v a  2  s.c  o  m*/

public class Main{
        /// <summary>
        /// Calculate the distance between these 2 points
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double DistanceBetween(Point3D a, Point3D b) {
            Point3D direction = new Point3D();
            direction.X = b.X - a.X;
            direction.Y = b.Y - a.Y;
            direction.Z = b.Z - a.Z;

            return Math.Sqrt(direction.X * direction.X +
                             direction.Y * direction.Y +
                             direction.Z * direction.Z);
        }
}

Related Tutorials