Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualStackout

Posted 18 May 2012 - 09:48 PM

The distance between two Vector3d you could use the Euclidian Distance Formula in 3d space.

Try this simple line of code:

public float DistanceBetweenVectors(Vector3 v1, Vector3 v2)
{
		  var distance = Math.pow((v1.x - v2.x), 2) + Math.pow((v1.y - v2.y), 2) + Math.pow((v1.z - v2.z), 2);
		  return (float)Math.sqrt(distance);
}

static void Main(string[] args)
{

	 Console.WriteLine("Distance between two v1 (2, 3, 2) and v2 (3, 3, 3) is: {0:F2}", DistanceBetweenVectors(new Vector3(2, 3, 2), new Vector3(3, 3, 3)));
	 Console.ReadLine();

}

You can also put a Vector2 in the distance formula, just create an overload for the same function and just take out the (v1.z - v2.z) and you will get your distance between two vectors.

Cheers,
Stackout

#3Stackout

Posted 18 May 2012 - 06:00 AM

The distance between two Vector3d you could use the Euclidian Distance Formula in 3d space.

Try this simple line of code:

public float DistanceBetweenVectors(Vector3 v1, Vector3 v2)
{
		  var distance = (v1.x - v2.x) + (v1.y - v2.y) + (v1.z - v2.z);
		  return (float)Math.sqrt(distance);
}

static void Main(string[] args)
{

	 Console.WriteLine("Distance between two v1 (2, 3, 2) and v2 (3, 3, 3) is: {0:F2}", DistanceBetweenVectors(new Vector3(2, 3, 2), new Vector3(3, 3, 3)));
	 Console.ReadLine();

}

You can also put a Vector2 in the distance formula, just create an overload for the same function and just take out the (v1.z - v2.z) and you will get your distance between two vectors.

Cheers,
Stackout

#2Stackout

Posted 18 May 2012 - 06:00 AM

The distance between two Vector3d you could use the Euclidian Distance Formula in 3d space.

Try this simple line of code:

public float DistanceBetweenVectors(Vector3 v1, Vector3 v2)
{
		  var distance = (v1.x - v2.x) + (v1.y - v2.y) + (v1.z - v2.z);
		  return (float)Math.sqrt(distance);
}

static void Main(string[] args)
{

	 Console.WriteLine("Distance between two v1 (2, 3, 2) and v2 (3, 3, 3) is: {0:F2}", DistanceBetweenVectors(new Vector3(2, 3, 2), new Vector3(3, 3, 3)));
	 Console.ReadLine();

}

You can also put a Vector2 in the distance formula, just create an overload for the same function and just take out the (v1.z - v2.z) and you will get your distance between two vectors.

Cheers,
Stackout

#1Stackout

Posted 18 May 2012 - 05:56 AM

The distance between two Vector3d you could use the Euclidian Distance Formula in 3d space.

Try this simple line of code:

public float DistanceBetweenVectors(Vector3 v1, Vector3 v2)
{
		  var distance = (v1.x - v2.x) + (v1.y - v2.y) + (v1.z - v2.z);
		  return (float)Math.sqrt(distance);
}

static void Main(string[] args)
{

	 Console.WriteLine("Distance between two v1 (2, 3, 2) and v2 (3, 3, 3) is: {0:F2}", DistanceBetweenVectors(new Vector3(2, 3, 2), new Vector3(3, 3, 3)));
	 Console.ReadLine();

}

Cheers,
Stackout

PARTNERS