Subtracting two points, the math.

$\begingroup$

I would like to confirm the math of subtracting two points. I've looked online but all of the sources I have seen want to end up with a vector, I need to end with a point.

I am looking at this function in this link,

/* Calculate the intersection of a ray and a sphere The line segment is defined from p1 to p2 The sphere is of radius r and centered at sc There are potentially two points of intersection given by p = p1 + mu1 (p2 - p1) p = p1 + mu2 (p2 - p1) Return FALSE if the ray doesn't intersect the sphere.
*/
int RaySphere(XYZ p1,XYZ p2,XYZ sc,double r,double *mu1,double *mu2)
{ double a,b,c; double bb4ac; XYZ dp; dp.x = p2.x - p1.x; dp.y = p2.y - p1.y; dp.z = p2.z - p1.z; a = dp.x * dp.x + dp.y * dp.y + dp.z * dp.z; b = 2 * (dp.x * (p1.x - sc.x) + dp.y * (p1.y - sc.y) + dp.z * (p1.z - sc.z)); c = sc.x * sc.x + sc.y * sc.y + sc.z * sc.z; c += p1.x * p1.x + p1.y * p1.y + p1.z * p1.z; c -= 2 * (sc.x * p1.x + sc.y * p1.y + sc.z * p1.z); c -= r * r; bb4ac = b * b - 4 * a * c; if (ABS(a) < EPS || bb4ac < 0) { *mu1 = 0; *mu2 = 0; return(FALSE); } *mu1 = (-b + sqrt(bb4ac)) / (2 * a); *mu2 = (-b - sqrt(bb4ac)) / (2 * a); return(TRUE);
}

specifically at the comments at the top of the function.

I have programmatically found my mu and now need to apply them to the points. So to make sure subtracting $(x_1, y_1)$ from $(x_2, y_2)$ would go $$(x_1-x_2,\quad y_1-y_2)$$ Then applying mu to a point would just be

$$(x\cdot\mu,\quad y\cdot\mu)$$

$\endgroup$

2 Answers

$\begingroup$

The "subtraction" of two points does produce a vector in the way you are describing. The idea is that this subtraction gives you the displacement vector between the two points. So if we have $P=(x_1,y_1)$ and $Q=(x_2,y_2)$ then the operation: $$P-Q = (x_1 - x_2, y_1- y_2)$$ is the vector that when you add it to the point $Q$ it will get you to the point $P$.

In this context the operations you are expecting hold true. That is the operation of vector addition and subtraction as well as scalar multiplication.

$\endgroup$ $\begingroup$

In this context, points - given by their coordinates in 3-space - are identified with vectors, thus justifying the calculations made.

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like