Focus the camera on the "average point" of moving entities

Hi :slight_smile:

I have some moving entities on the screen (could be anywhere between 2 and 6). I would like to be able to focus the camera on the average point of every subset of them (meaning, their 3 dimensional “mean” point on the globe). For convenience, I have full control over the entire data of each entity, meaning I know exactly where they are at each given time.

There are some ideas coming up to my mind, and I’d like some advices on how to encounter this problem.

  • How “expensive” can the creation of more entities be? . When it comes to only 2, I could theoretically create a third entity which is always in their middle point (using ReferenceProperty and PositionPropertyArray), and just hide it. If I scale it up from 2 to 4, I would have to create 11 more entities, just to hide them!

  • I think that using CallbackProperty is my way to go here. Problem is, I need the camera to be free when focusing. I can’t just calculate the appropriate frame each time, rather I need some solution to handle the camera’s position in each “tick” in a smooth way.

Thanks in advance!

What I have understood is you have group of moving entities and each group has a median point and you want to focus camera on those median points.

You can check this post to calculate midpoint between 2 cartesian3 values.

You can use addEventListener to perform actions on each tick:

viewer.clock.onTick.addEventListener(function (clock) {
// your stuff here...

I suggest you to create a sandcastle example for our better understanding.

  • Regards

Hi, thanks for your answer!

Jusr realized that I can just go with the first solution and just remove the old hidden entity whenever I create a new one :man_facepalming:t2: