Calculate Radius of a sphere
Okay...I got a node in a quad tree.
I have 4 points which make up its bounding box..
I can get the center of the 4 points easily. That center can be used as the center of the sphere.
I am wondering how I can get the radius which would indeed cover those four points, or at least just past those 4 points. The sphere in most case's should be a bit bigger I think.
Any help at all though?
So far what I am doing is taking the magnitude of the a vector and dividing it by 2.
That works in most cases's...see
P1 (4,0) P3 (8,0)
P2 (4,4) P4 (8,4)
Center = ((P4 - P1) / 2) + P1 = (4,4 / 2) + 4,0 = (2,2) + (4,0) = 6,2
Center = 6,2 is indeed correct if you wish to picture the grid.
r^2 = x^2 + z^2 (the points I shall use will be from P4)
r^2 = 8^2 + 4^2
r^2 = 64 + 4
SqrRt(r) = SqrRt(68)
r = 8.2462112512353210996428197119482 / 2
r = 4.1231056256176605498214098559741
Indeed r as 4.1 is JUST outside the bounding box...is this correct????
Re: Calculate Radius of a sphere
I don't understand. Can you do us a picture in mspaint? :bigyello:
Re: Calculate Radius of a sphere
Halsafar,
After reading through you post, we need some clarification here.
1) Is your "bounding box" always square (or even rectangular) as in your example?
2) Are you looking for the smallest circle that encompasses all four points?
3) You suggest that the circle might need to be "a bit bigger" to take in the points, how much bigger?
Incidentally, if you are looking for the smallest circle whose radius takes in all four points, your calculated radius should be SqrRt(8).
I guess, as wossname suggested, your needs are a little unclear. Anything you can add will be of help.
Steve
1 Attachment(s)
Re: Calculate Radius of a sphere
Sorry about that. I do see how unclear I am.
This picture should help.
The radius is what I need to find.
The center of the node is easy.
The radius that encompas's past the 4 points....So the entire box is in the sphere.
Re: Calculate Radius of a sphere
So basically you want "the smallest bounding circle for any given rectangle"?
Assuming P1 is top left point, P2 top right, P3 bottom left, P4 bottom right...
Circle.Centre.X = (P1.X + P2.X) / 2
Circle.Centre.Y = (P1.Y + P3.Y) / 2
Circle.Radius = Sqrt((P4.X - Circle.Centre.X)2 + (P4.Y - Circle.Centre.Y)2)
Re: Calculate Radius of a sphere
Alright sounds good.
Thank you very much.