Psuedocode:

```
bool Sphere::inside(Vector3 point) {
if(distance_from(this.center, point) <= this.radius) {
return true;
}
return false;
}
```

Please log in or register to post a reply.

Psuedocode:

```
bool Sphere::inside(Vector3 point) {
if(distance_from(this.center, point) <= this.radius) {
return true;
}
return false;
}
```

Computing the distance is expensive as it requires a square root. However, both sides of the inequality can be squared so you lose the square root and end up with basically this:

(x - x0)² + (y - y0)² + (z - z0)² <= r²

@Nick

Ahh I see. you are essentially applying a pythagorean theorem approach twice. once applied to a triangle who’s two sides are along the x and y planes, and once using either the x or y plane and z plane.

Very nice. Thanx!

Yep, that’s right. That’s the standard way to measure distance between two points in 3D space.

Since you seem to be new to 3D math, you should check out vectors and matrices.

@Reedbeta

I am very new to 3d math in concept. I am not new to programming though. Most of the math I’ve done in code has involved business logic. I’ve taken an interest in 3d graphics only recently. I’ve been considering attempting to learn how to code with a 3d engine, but before doing that, I thought it’d be best to learn the basics first. That link to vectors and matrices is pretty much where I am at on the learning curve thus far.

- Upcoming Multiplatform Game Program...
- Our first game - looking for feedbacks
- Network Emulation Tool
- Trouble with accessing GLSL array
- Fiction
- Game Programming Patterns: Bytecode
- Interactive WebGL Water Demo
- Skeletal Animation Tutorial with GP...
- Unreal Engine 4
- Microsoft xbox one selling poorly

Does anyone know of an algorithm or code sample that can determine if a point in 3d (x,y,z axis) space occurs within a 3d sphere who’s center point and radius is known?