Wednesday 15 August 2012

geometry - Generate Polygon from Set of Angles in Python? -


Hello all (I hope I'm not doing anything wrong after first posting) ... < / P>

I am trying to generate 3 sets 2l randomly 3 sets of convex polygon so that each side of each polygon l predefined lines of one of If someone knows how to do this (without the help of computational geometry package like CGAL or Shapley, without the help or without), then it would be great.

I 2l angle (direction of each line, and direction for each row + pi parallel sides). For each polygon, I want to select 3 to 2l angles randomly from this list, in order to be sorted in ascending order, so that to ensure that no angle PE is no different than before, although the angle is able to define a polygon, after that I am unable to ensure that I am producing a polygon and convex and only the sides Which I have chosen, my code currently looks like this:

  Generate DRF (L, N, W, H): "" In the Exx Plane, Generate polygon. "" L = [] polygon = [] while lane (l)    

The first obstacle is the sum of the angles of a convex polygon

180 * (N -2) degrees, where N is the number of sides of your convex polygon [].

second obligation for Gi two lines, you have two options for your angle:  Angel Choice

You must choose Green Angle The criteria for your selection are not very clear in your statement, so I can not believe that there is a mistake or not. To select a good angle, I think that the simplest thing to do is to consider the directional vector for each line. Calculate u to the vector with the direction of your last line (pointing to direction). Compute v , a direction vector of the new line. If (u ^ v) & gt; 0 , v is not oriented correctly, so you want to move -v . Otherwise, if (u ^ v) & lt; 0 , v is correctly oriented Description: u ^ v = ux * vy -uy * vx

So this leads us to our second hurdle. Looking forward to the side vector and u_next direction, we have the u ^ u_next & lt; Keeping in mind u ; 0 .

I think the second hurdle is enough, we will not need it first (but still good to know about common sense).

What to do Here's what I will do for you:

  1. Select the Random Line Direction Vector u0 Calculate as if u0.x> 0 . Start with the list of direction vector with listDV Note: if choose u.x = 0 , then u such as u.y & gt; 0 .
  2. While ( listDV.last ^ list.dV.first <0 ) {Choose the Random Line, Direction Vector u like < Code> listDV.last ^ u & lt; 0 }
  3. Discard the last vector of listDV .

    So now you have a list of direction vectors, which are parallel to your lines. This list creates convex polygon

    Next your polygon will be formed if you need help on this, then tell me!

No comments:

Post a Comment