Skip to main content
Inspiring
December 3, 2021
質問

Calculate geometric center of mask

  • December 3, 2021
  • 返信数 2.
  • 478 ビュー

Here's a tough one (I think).

Is it possible to calculate the geometric centre of a mask via expression? I need to sample a colour in that exact position on every frame.

Thanks, Wim

このトピックへの返信は締め切られました。

返信数 2

Mylenium
Legend
December 3, 2021

Should be easy enough by adding all vertices to an array and then iterate through them, push the calculated centers into a new array and then repeat this iteratively until you arrive at only three points for the final centroid. Here's a quick non-AE example that I found that provides the base to work from:

 

https://stackoverflow.com/questions/65188028/centroid-of-a-polygon-script

 

This would then need to be expanded with teh specific AE stuff to grab the mask data and create proper arrays to retrieve the data.

 

Mylenium

Mylenium
Legend
December 3, 2021

Entireley depends on what you mean by "center". Center of gravity? Shortest distance to the perimeter? Center of the circumscribing circle? Averaged center in a virtual grid? Intersection of all vertex connections? Center of the bounding box? Others? See, it's all down to what you exactly see as the "center" and depending on what shape(s) your mask(s) have, the answer could be simple or infinitely complicated. More info and perhaps a screenshot would perhaps help to provide a more straightforward answer.

 

Mylenium

Wim_Schalley作成者
Inspiring
December 3, 2021

Hi, it's the centre of gravity I'm after. Or the 'centroid', in mathspeak.

m1b
Community Expert
Community Expert
December 13, 2021

Here's an example written for Illustrator. Might be easy to adapt to AE.

- Mark