# 生成正多边形

## 思路

`n`多边形应该是是建立在上的，
`θ`随着n而变化，有`θ=2π/n`关系，

## Pycode.

``#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date    : 2017-11-12 21:11:39 # @Author  : Zero (Zeroto521@gmail.com) # @Link    : None # @Version : \$Id\$ ``
``import pylab as pl %matplotlib inline ``
``def polygon(n=3, startX=100, startY=0, r=100):     """     Ploygon for docstring.     Get ploygon x and y postions.     ---------------------      Paramter         n: int, polygon's sides, default 3.         startX: int, fitst x postion, default 100.          startY: int, fitst y postion, default 0.         startX: int, fitst x postion, default 100.          r: int, radius, default 100.           Returns         x, y: list, x and y contain all postions.      """     theta = 2 * pl.pi / n     x = [startX - r * pl.sin(theta * i) if i >          0 else startX for i in range(n + 1)]     y = [startY + r - r * pl.cos(theta * i)          if i > 0 else startY for i in range(n + 1)]     return x, y ``
``x, y = polygon(3) pl.plot(x, y) ax = pl.gca() ax.set_aspect(1)  # Make xticks' length qeual to yticks'length. ``

SourceCode