0

What is a way that I can calculate the width of a convex polygon given its vertices and some angle? The purpose of this is to find the cross sectional width of a polygon moving at some velocity in order to calculate some kind of air drag during a simulation.

I guess the biggest problem is that I don't have more than a basic understanding of geometry right now, so I'm not sure I would recognize the solution if I saw it. The closest algorithms I could find deal with finding the minimum width of a polygon, but I'm really looking for the width in the direction of some velocity. I'm a bit stumped.

ire_and_curses
  • 68,372
  • 23
  • 116
  • 141
kevinrstone
  • 266
  • 2
  • 12

1 Answers1

2

Just rotate all vertices of polygon by needed angle and find difference of maximum and minimum Y-coordinates of vertices (for example, for zero angle width along X-axis is Ymax-Ymin).

Rotation_matrix is here. Rotated coordinates of vertice are:

  x'=x*Cos(Fi)-y*Sin(Fi)
  y'=x*Sin(Fi)+y*Cos(Fi)

Note that you need to find only y'

MBo
  • 77,366
  • 5
  • 53
  • 86
  • 1
    Your method is good, but shouldn't the width along the X axis be calculated with max(X') - min(x') instead of max(y') - min(y')? (I assume that width is the dimension in the horizontal x direction and height is the dimension in the vertical y direction.) – M Oehm May 26 '14 at 19:43
  • Thank you. I just tested it with some simple rectangles to make sure I have my head wrapped around it, and it seems legit. By the way, I believe M Oehm is right, in that I was looking for max(x')-min(x'). It all depends on how you interperet "width". – kevinrstone May 26 '14 at 21:21
  • Yes, I considered another interpretation of "width along direction", probably less intuitive... – MBo May 27 '14 at 03:27
  • Just for info, in case the number of vertices is large, it is possible to do this in O(Log(N)) operations rather than O(N) by exploiting convexity. –  May 27 '14 at 13:51