You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You don't need to use sqrt here. Sqrt is expensive.
// POINT/CIRCLE
boolean pointCircle(float px, float py, float cx, float cy, float r) {
// get distance between the point and circle's center
// using the Pythagorean Theorem
float distX = px - cx;
float distY = py - cy;
float distance = sqrt( (distX*distX) + (distY*distY) );
// if the distance is less than the circle's
// radius the point is inside!
if (distance <= r) {
return true;
}
return false;
}
You can just compare the squares easier and faster: return distX*distX + distY*distY <= r*r;
(Thanks for the book!)
The text was updated successfully, but these errors were encountered:
You don't need to use sqrt here. Sqrt is expensive.
You can just compare the squares easier and faster:
return distX*distX + distY*distY <= r*r;
(Thanks for the book!)
The text was updated successfully, but these errors were encountered: