# How does a point squared equal the radius squared?

I am working on a simple ray tracer but I don't understand some of the formulas.

One that is bugging me at the moment is this:

If a sphere is centred at origin, a point p lies on a sphere of radius r2 if
p*p = r2

Now, as I understand it, 'p' is a point in 3D space, (x,y,z), so how is it possible to square the point and have it equal the radius squared?

For what it's worth, I'm reading this article on calculating the intersection of a ray and a sphere.

• I think you should kick the ass of person who wrote p*p. One can not just use operators with vectors without mentioning, what his operator mean. It is much better to write it in "shader style" - dot(p, p), or in "math style" - p^T * p (where T is transposition and * is matrix multiplication). – Ivan Kuckir Jan 30 '13 at 10:13

There are two ways to "multiply" vectors: the dot product and the cross product.

In this case, they're using the dot product, and it is very easy to see that, if p is centered at the origin, then:

  dot(p, p)
= (p.x * p.x) + (p.y * p.y) + (p.z * p.z)
= mag(p) ^ 2 // per the pythagorean theorem


Now, if the magnitude of your vector happens to be the radius of the sphere, then your point will lie exactly in the sphere.

• Thanks so much for identifying the type of formula that's being used! – JDB Jan 30 '13 at 5:59
• @Cyborgx37 glad I could help. Just remember that, in mathematical notation, whenever there is a middle dot between two vectors, they're talking about the dot product, and when there is a cross, they're talking about the cross product. The asterisk as you put it has no standard meaning when operating with vectors. – Panda Pajama Jan 31 '13 at 2:31

You seem to have paraphrased the formula incorrectly. In vector algebra, there are several types of multiplication and they use different symbols. The original article uses the dot product (·) which is not equivalent to the generic multiplication symbol *. It also uses bold face to signify vectors as opposed to scalar quantities, i.e. is not the same as . In fact, as you rightfully noted, you cannot really 'square' a vector.

The formula as it was originally written is:

p · p = r²

If two vectors point in the same direction, as p and p obviously do, their dot product equals the square of their absolute values or 'lengths'. By definition, any point at a distance r from the origin lies on the sphere with radius r centered at the origin. Ergo, if the square of a vector's length equals the square of this sphere's radius (p · p = r²), then the point lies on a sphere with radius r. The article mentions the sphere's radius is ; this is incorrect.

• +1 I was unfamiliar with the symbols. The dot looked like the multiplication symbol (which * resembles). @PandaPajama's answer pointed me in the right direction. – JDB Jan 30 '13 at 21:56
• @Cyborgx37 In most cases the multiplication symbol is left out. – Sidar Jan 31 '13 at 1:54