I have given a set of points. The “center” of this set of points i will set to be just some sensible center-point. Maybe the mass-center, but preferably the center of the smallest possible sphere containing all the points (allthough I am not sure how to find this).
Now I would like to move my camera so that it looks at the center and so that all points in the set are visible (without changing the aspekt or field of view of the camera).
However I do not want to have to move too far away from the center either. Actually I would like to move only the smallest distance possible away from the center in order to still have all points visible.
Any suggestions on how to do this?
Make a bounding box by testing all points for the highest and lowest x, y and z value.
From that value you can work out the centre pretty fast.
the size of the bounding box can also be used to determine how far the camera should move, something like this,
cameraDistance=boundingBoxSize * someMultiplicator;
Adjust with someMultiplicator.
It’s only normal to loose a few close points at the edges.
If you have to abolutely get all the points in there, you can use some trigenometry to work out how far the camera should be to include all points (but im no good at that so other people have to take this and run with it).
very difficult problem as screens are typically smaller hight wise than width-wise so to do perfect would be difficult me thinks.
my guess would be measure dist bvetween all points and choose the 2 with greatest distance + then aim at the center of this, using the up vector for the camera as the perpudicuclar vcetor to that vector between them.
also another method like zeoverlord (crap name, actually terible german myabe ok, yah, i am ze overload) theres plenty of methods of finding the smallest bounding sphere of points eg see magic software website/code
Thanks for your replies.
Ended up using the aproximate algorithm listed here:
To find a good aproximation of the the minimal bounding sphere. Once I have this, it is pretty easy to calculate where to put the camera using a bit of trig and ofcourse minding the aspekt-ratio as zed points out.
I would just like to add that my first idea was something like zed’s: to find the two points furthest apart and make the center-point the point in the middle between these points.
However this doesnt give very good results I think. Consider a triangle. Using this idea the center-point would always be on one of the edges of the triangle, instead of somewhere in the middle as is propably what you would like.