0

I'm sorry if this turns out to be a trivial answer I have not been able to figure out how to find the orientation of an irregular polygon (given as an array). By orientation I mean the angle between 0 and the long axis of the object.

Searching around I found a function in MatLab called regionprops() that is almost exactly what I need.

https://www.mathworks.com/help/images/ref/regionprops.html

Is there a JavaScript equivalent that I just cannot find, or would it be advisable to learn how to include MatLab in my project?

  • What have you tried? How are you creating the polygon? – Brett DeWoody Jul 17 '17 at 22:10
  • The polygon is the convex hull of a set of markers placed on Google maps. So far I've found the centroid of that shape but passed that I'm clueless to the math behind finding the orientation. I've tried using a library called robust-orientation but no luck. – Sean Chowdhury Jul 17 '17 at 22:55
  • see [How to Compute OBB of Multiple Curves?](https://stackoverflow.com/a/42997918/2521214) – Spektre Jul 18 '17 at 08:09

1 Answers1

0

Seems you need to calculate image moments.

Information about image orientation can be derived by first using the second order central moments to construct a covariance matrix.

Also consider principal components analysis

MBo
  • 77,366
  • 5
  • 53
  • 86