View Full Version : Overviewing a set of points
07-07-2006, 06:14 AM
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?
07-07-2006, 08:28 AM
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
07-09-2006, 03:29 AM
Originally posted by zed:
(crap name, actually terible german myabe ok, yah, i am ze overload) Ya crap iz da name, but it's old, i had it for ages.
It's also the one i use when "overlord" is occupied.
I allso go by the name zeo on some places, but those are few since most places needs at least 4 chars in the username.
07-09-2006, 05:11 AM
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.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.