Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branches 'origin/u/jdemeyer/ticket/17131' and '…
Browse files Browse the repository at this point in the history
…origin/u/jdemeyer/ticket/17133' into ticket/17130
  • Loading branch information
jdemeyer committed Oct 11, 2014
3 parents 6d10729 + 0001941 + 24020fe commit b6e1ed4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/sage/combinat/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3101,11 +3101,16 @@ def to_exp(self, k=0):
[1, 2, 1]
sage: Partition([3,2,2,1]).to_exp(5)
[1, 2, 1, 0, 0]
TESTS::
sage: [parent(x) for x in Partition([3,2,2,1]).to_exp(5)]
[Integer Ring, Integer Ring, Integer Ring, Integer Ring, Integer Ring]
"""
p = self
if len(p) > 0:
k = max(k, p[0])
a = [ 0 ] * (k)
a = [ZZ.zero()] * k
for i in p:
a[i-1] += 1
return a
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3605,7 +3605,7 @@ def volume(self, engine='auto', **kwds):
2.37764129...
sage: P5 = polytopes.regular_polygon(5, base_ring=QQ)
sage: P5.volume() # rational approximation
3387471714099766473500515673753476175274812279494567801326487870013/1424719417220622426561086640229666223984528142237277803327699435400
143675742936485206271005807482349119225365261915467953640852591/60427846494832899490396166935397049960830782710733164218307960
sage: _.n()
2.37764129...
Expand Down
28 changes: 21 additions & 7 deletions src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
########################################################################


from sage.rings.all import Integer, QQ, ZZ, RDF
from sage.rings.all import Integer, RR, QQ, ZZ, RDF
from sage.matrix.constructor import matrix
from sage.modules.free_module_element import vector
from sage.combinat.permutation import Permutations
Expand Down Expand Up @@ -121,27 +121,41 @@ def _pfunc(i,j,perm):
@rename_keyword(deprecation=11634, field='base_ring')
def regular_polygon(self, n, base_ring=QQ):
"""
Return a regular polygon with n vertices. Over the rational
Return a regular polygon with `n` vertices. Over the rational
field the vertices may not be exact.
INPUT:
- ``n`` -- a positive integer, the number of vertices.
- ``field`` -- either ``QQ`` or ``RDF``.
- ``base_ring`` -- a ring in which the coordinates will lie.
EXAMPLES::
sage: octagon = polytopes.regular_polygon(8)
sage: len(octagon.vertices())
8
sage: polytopes.regular_polygon(3).vertices()
(A vertex at (-125283617/144665060, -500399958596723/1000799917193445),
A vertex at (0, 1),
A vertex at (94875313/109552575, -1000799917193444/2001599834386889))
sage: polytopes.regular_polygon(3, base_ring=RealField(100)).vertices()
(A vertex at (0.00000000000000000000000000000, 1.0000000000000000000000000000),
A vertex at (0.86602540378443864676372317075, -0.50000000000000000000000000000),
A vertex at (-0.86602540378443864676372317076, -0.50000000000000000000000000000))
sage: polytopes.regular_polygon(3, base_ring=RealField(10)).vertices()
(A vertex at (0.00, 1.0),
A vertex at (0.87, -0.50),
A vertex at (-0.86, -0.50))
"""
npi = 3.14159265359
try:
omega = 2*base_ring.pi()/n
except AttributeError:
omega = 2*RR.pi()/n
verts = []
for i in range(n):
t = 2*npi*i/n
verts.append([sin(t),cos(t)])
verts = [[base_ring(RDF(x)) for x in y] for y in verts]
t = omega*i
verts.append([base_ring(t.sin()), base_ring(t.cos())])
return Polyhedron(vertices=verts, base_ring=base_ring)


Expand Down

0 comments on commit b6e1ed4

Please sign in to comment.