0
votes

What is the general algorithm for solving the problem of determining coordinates of vertices of an arbitrary polygon by lengths of sides and angles between them. For example, we have an array of lengths of sides [10 10 10 10] and an array of angles [90 90 90 90], we need to get an array of vertex coordinates [[0 0] [10 0] [10 10] [0 10]]. Check data:

  1. l=[10 10 10] a=[60 60 60] => [[0 0] [10 0] [5 8.66]]
  2. l=[20 14.14 10 10] a=[45 135 90 90] => [[0 0] [10 0] [20 10] [0 10]

It does not matter where on the coordinate grid the solution will be located. It also doesn't matter the direction of rotation (clockwise or counterclockwise). The main thing is that the resulting set of coordinates corresponds to the original conditions. Any of the solutions from the possible set is of interest.

Clarification. Consider that the first edge of the polygon lies on the X-axis and the vertices have coordinates [0 0] [L 0], where L is the length of the edge. Clockwise bypass.

2
What have you tried so far? - Ripi2
Lengths and angles in betwen is not enough. Consider you can rotate the polygon and the lenghts and angles are the same, but coordinates change. - Ripi2
What @Ripi2 said. At a minimum you also need 2 absolute coordinates, or the starting coordinates and some absolute direction/angle like the starting or ending direction. - RBarryYoung
added clarification so that the problem has only one solution. - ZOS
I think you also need to specify 'angle between them' more closely. For example if the first three coordinates were (0,0) (L,0), (L,M) and L,M>0 would the angle between the first two sides be 90 degrees? How about if L>0, M<0? - dmuir

2 Answers

3
votes

Let's call "Ang" the angle of an edge relative to X-axis. This value is not given, but can be calculated by summing all in-between-edges angles previous to this edge.

So, for edge 1 we have "Ang= 0" (assumption). For edge 2 we know the inner angle (say "a2") with edge 1. So for this edge we have "Ang= 0 + a2".
If inner angle for edge 3 is "a3" then we have "Ang= 0 + a2 + a3". And so on for the rest of edges.

You say that the angles between edges are given clockwise. Because the trig functions use a clockwise system we must change the sign of the angles in-between.

To caculate X,Y components of an edge we'll use trigonometrics "cos(a)" and "sin(a)" where "a" is angle counter-clockwise measured.
These components are

x = L * cos(a)
y = L * sin(a)

where L is the length of the edge.

The coordinates are those of previus edge added with these components.

Putting it all together, in pseudo code we have:

//First vertex
x(0) = 0
y(0) = 0

Ang = 0;

for i=1 to numOfVertices {
    Ang = Ang - a(i)
    x(i) = x(i-1) + L(i) * cos(Ang)
    y(i) = y(i-1) + L(i) * sin(Ang)
}

Notice a(i). It's the angle with the previous edge. This means that the array of angles must start with '0' which corresponds with the angle of the first edge relative to X-axis.
Also, be aware of using degrees or radians in trigonometric functions.

0
votes

Something like this maybe

import numpy as np
import matplotlib.pyplot as plt

def get_vertices(a, l):
    n = l.size
    p = np.empty((n+1,2), dtype=float)
    p[0,:] = np.array([0,0])
    p[n-1,:] = np.array([0,0])
    p[1,:] = np.array([l[0] ,0])
    angle = 0
    for i in range(1, n-1):
        angle = angle + np.pi - a[i]
        v_edge = l[i]*np.array([np.cos(angle), np.sin(angle)])
        p[i+1,:] = p[i,:] + v_edge
    # correcting for the input data, the lase edge and the first and last angles
    l[n-1] = np.linalg.norm(p[n-1,:])
    a[0] = np.arccos(p[n-1, 0]/l[n-1])  
    a[n-1] =  angle - a[0] 
    return p

a = np.array([0, np.pi/2, 75*np.pi/180, np.pi/2])
l = np.array([1, 1, np.sqrt(6)/2, np.sqrt(2)/2])

#a = np.array([0, np.pi/2, 75*np.pi/180, 0])
#l = np.array([1, 1, np.sqrt(6)/2, 0])
  
x, v = get_vertices(a, l)

fig, axs = plt.subplots(1)
axs.plot(x[:,0], x[:,1], 'b')
for p in x:
  axs.plot(p[0], p[1], 'ro')
axs.set_aspect('equal')
plt.grid()
plt.show()

One comment: the data you want to give the algorithm contains three redundancies. Basically, for a polygon of n vertices, if you have data for n angles and n edges, then there are 3 equations, one for an edge and two for angles of that edge with its adjacent edges. So the independent input parameters should be more like n-1 edges and n-2 angles.

I made the algorithm correct your angle and edge data, if necessary.