PDA

View Full Version : Im slightly stuck with Vectors



silverspawn
12-17-2010, 11:50 AM
Im trying my hand at vectors trying to grasp more about object in a 2d and 3d space but struggling wondering if anyone could help at all:) got the basic concept out the way of vectors to having hard time grasping the next stage

If a 2d line passes though Po(10,15) and P1(150,300) I am trying to find the equation of the line ?

And also find the distance from point P(-500,400) to the line?

Thnaks in advance

Maya
12-25-2010, 10:39 PM
pythagorean theorem for calculating distance between points in 3d space .

square_root(x_diff*x_diff + y_diff*y_diff + z_diff*z_diff)

with this type of formula the * calculations are executed before the + calculations so you could bracket these and do them first .

in your case with 2d you can drop off the z calculation

Maya
12-25-2010, 10:57 PM
One thing i forgot to post was the way i do it in c++ if you know anything about c++ classes then give this a try .

#
public int Distance2D(int x1, int y1, int x2, int y2)
#
{
#
// ______________________
#
//d = √ (x2-x1)^2 + (y2-y1)^2
#
//
#

#
//Our end result
#
int result = 0;
#
//Take x2-x1, then square it
#
double part1 = Math.Pow((x2 - x1), 2);
#
//Take y2-y1, then sqaure it
#
double part2 = Math.Pow((y2 - y1), 2);
#
//Add both of the parts together
#
double underRadical = part1 + part2;
#
//Get the square root of the parts
#
result = (int)Math.Sqrt(underRadical);
#
//Return our result
#
return result;
#
}