From Tobias:
what i meant is that distance or length is the sqrt of the sum of squares
but if you square both sides of the statement, you don't need the square root at all
you only have to calculate the sum of squares
let's say we have a - operator in coordinates, which returns a coordinate(x - coord.x, y - coord.y, z - coord.z)
you can do
From Tobias: what i meant is that distance or length is the sqrt of the sum of squares but if you square both sides of the statement, you don't need the square root at all you only have to calculate the sum of squares let's say we have a - operator in coordinates, which returns a coordinate(x - coord.x, y - coord.y, z - coord.z) you can do
bool Coordinate::withinDistance(const Coordinate &coordinate, const double distance) const { Coordinate diff = this->operator-(coordinate); return (std::abs(diff.x) < distance) && (std::abs(diff.y) < distance) && (std::abs(diff.z) < distance) && (diff.x diff.x + diff.y diff.y + diff.z diff.z < distance distance); }
now that last line should be a function call, but i inlined the function to illustrate that sqrt isn't neccessary