Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I want to know if there is any general formula to find out vertices (co-ordinates) of a polygon (3 or more equal sides) when following is given:

Co-ordinates of one of the vertices 
Center point (distance between each vertex and center point is equal)

For example, what would be A and B vertices of following equilateral triangle:

(For equilateral triangle i assume that center point = centroid)

     A
    /\
   /  \                 Center point = (2, 5)
  /____\ 
 B      C (4, 6)

Thanks for help.

Regards

share|improve this question

migrated from stackoverflow.com Apr 27 '11 at 14:53

This question came from our site for professional and enthusiast programmers.

1  
Yep, it's just a linear transformation ;) –  Blender Apr 27 '11 at 5:53
1  
I think you need more assumptions in your hypothesis. With those assumptions alone, you still can't determine n, where n is the number of sides (or vertices) of your regular polygon. If you look closely at the answers you've been given as well as at mathworld.wolfram.com/RegularPolygon.html, you'll notice that it's assumed n is known. However, you don't have that assumption in your hypothesis, which means those formulas won't work unless n can be found to depend on the coords of one vertex and the center. (But I'm pretty sure that last part is impossible.) –  Rodney Apr 27 '11 at 13:12
    
The problem's underdetermined. At the very least, you want to be able to form the isosceles triangle that comprises a "slice" of the regular polygon you want, and just two pieces of information isn't enough to uniquely determine that triangle. –  J. M. Apr 27 '11 at 15:16

2 Answers 2

up vote 4 down vote accepted

If you have a polygon with equal sides and equal distance from center to all vertices it seems to be a regular convex polygon

EDIT I've found much easier way.

Assume that center of the polygon has coordinates (x_0,y_0) and known vertice has coordinates (x_n,y_n). Also assume that we are considering n-sided polygon.

Coordinates of i-th vertce (0<i<n) can be calculated using this formulae

x_i = x_0+R*cos(a+2*Pi*i/n)
y_i = y_0+R*sin(a+2*Pi*i/n)

where

     _______________________
R = v(x_n-x_0)^2+(y_n-y_0)^2
a = acos((x_n-x_0)/R)

According to your example computations using formula above shows that

A=(4, 6)
B=(0.1339745962155614, 6.2320508075688776)
C=(1.8660254037844377, 2.7679491924311228)

You can check (e.g. using this calculator) that distances between A and B, B and C, C and A are the same and equal to 3.8729833462074166. Also yu can calculate distance between center and each vertice and see that they all will be the same.

==================

That means you can find length of the side of such polygon using this formula a=2Rsin(Pi/n), where R is a distance between center c of your poly and its known vertice p.

   _____________________________
R=v(c.x - p.x)^2 + (c.y - p.y)^2

So you will have a triangle based on center c of your poly and its first p and second s vertices. Since you know coordinates of c and p and length of all sides of this triangle (distance between c and p is R, distance between p and s is a and distance between s and c is again R) you can determine coordinates of s.

share|improve this answer
1  
To get $a$, the starting angle, it is better to use $Atan2(y_n-y_0,x_n-x_0)$ Atan2 sorts out the quadrants for you, while for Acos you need to do it yourself –  Ross Millikan Apr 27 '11 at 16:00
    
Thanks a lot for help @Konstantin Mikhaylov and @Ross Millikan. I used atan2 to find a. Thanks again. Regards –  user10156 Apr 27 '11 at 23:32

The coordinate gives you the distance from each point to the center:

            _______________________________
distance = v (c.x - p.x)^2 + (c.y - p.y)^2

Now that you know the distance, you can construct the polygon. I'm not sure what you mean by "find out vertices", so I'll just assume you want to find the coordinate of an arbitrary vertex (hexagon in this example).

   _____. v
  /   r/\
 /    /  \
 \       /
  \_____/

Just assume it's centered at the origin and subdivide the unit circle into that many "slices", starting from 0:

v(n, k, c, p) = (cos(pi * (n/k)), sin(pi * (n/k))) Unit circle
        * sqrt((c.x - p.x)^2 + (c.y - p.y)^2)  Orig. length
        + (c.x, c.y)                           Move center

This spits out the coordinate of the kth vertex in a n sided polygon centered at c with a point p. So in a very verbose OOP notation:

def v(n, k, c, p):
  z = Point(0, 0)
  d = sqrt((c.x - p.x)^2 + (c.y - p.y)^2) # Distance from
                                          # vertex to center

  z.x = cos(2pi * (n/k))  # Coordinates of point
  z.y = sin(2pi * (n/k))  # on unit circle.

  z.x *= d # Unit circle has a radius of 1.
  z.y *= d # You need a radius of d.

  z.x += c.x # Center the point at c (the center of
  z.y += c.y # the original polygon, as it's at the origin.

  return z

No guarantees that this works ;)

share|improve this answer
    
And your algorithm doesn't work correctly. Take following example. Square with vertices in (-1, 1), (1, 1), (1, -1), (-1, -1). It is easy to see that its center is located in (0, 0). So assume that we have square with center in (0, 0) and its first vertice p is in (1, 1). –  Konstantin Mikhaylov Apr 27 '11 at 12:03
    
Call v(4, 1, (0, 0), (1, 1)) will return (1.4142135623730951, 0). Call v(4, 2, (0, 0), (1, 1)) will return (1.4142135623730951, 0). Call v(4, 3, (0, 0), (1, 1)) will return ( -0.70710678118654646, 1.2247448713915898). Call v(4, 1, (0, 0), (1, 1)) will return (1.4142135623730951, 0). –  Konstantin Mikhaylov Apr 27 '11 at 12:14
    
Apparently there is a mistake in your formulae z.x = cos(2pi * (n/k)). It should be z.x = cos(2pi * (k/n)). But even after this edit your algorithm will produce results which could be incorrect (since first point p doesn't alwys have coordinates (c.x, c.y+d)). –  Konstantin Mikhaylov Apr 27 '11 at 12:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.