CSharp examples for Microsoft.Xna.Framework:Xna
Gets the distance from a point to a line in 3 space in Xna
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; using System.Text; using System.Linq; using System.Collections.Generic; using System;/*w w w . j a v a2s .c o m*/ public class Main{ /// <summary> /// Gets the distance from a point to a line in 3 space /// Reference: Wolfram Alpha /// </summary> /// <param name="pt">Point in 3 space</param> /// <param name="line">Line in 3 space</param> /// <returns>minimum distance from point to the line</returns> public static float distanceFromPointToLine(Vector3 pt, Ray line) { //Let two points in space define a line: Vector3 x1 = line.Position; Vector3 x2 = line.Position + line.Direction; return Vector3.Cross((x2 - x1),(x1 - pt)).Length()/(x2-x1).Length(); } }