How to draw a star (and more) in polar coordinates

The question of the formula for a polygon in polar coordinates regularly arises on thematic resources - and just as regularly remains without a clear answer. In the best case, a solution comes across through the remainder function - which is not "clean" from a mathematical point of view, since it does not allow performing analytical transformations on the function. Apparently, real mathematicians are too busy solving problems of the millennium and looking for a simple proof of Fermat's theorem to pay attention to such banal problems. Fortunately, in this matter, imagination is more important than knowledge, and to solve this problem you do not need to be a professor of topological sciences - school-level knowledge is enough.



The formula for an equilateral polygon in polar coordinates looks very simple

ρ=cos⁑(2sinβˆ’1⁑(k)+Ο€m2n)cos⁑(2sinβˆ’1⁑(kcos⁑(nΟ•))+Ο€m2n)



and has the following parameters:



Ο• - angle;

n - the number of convex vertices;

m- determines how many vertices the sides will lie on one straight line. Negative values ​​are also permissible for it - the sign will determine in which direction the star will bend;

k - rigidity - at k=0 we get a circle regardless of other parameters, for k=1 - a polygon with straight lines, at intermediate values ​​from 0 before 1- intermediate figures between a circle and a polygon.



With this formula, you can draw a star in two ways:



1)n=5,m=3





2) n=5/4,m=0... In this case, you need to make two turns instead of one:





Parameter m affects the polygon as follows (here it changes from -1 to 5):





Parameter k in animation:





Complex form and modifications



You can rewrite the original formula in a complex form, and, despite the presence of imaginary units in it, the value of the radius will still remain valid:



ρ=41/n(1βˆ’k2+ik)βˆ’1/n(1+(1βˆ’k2+ik)2/neiΟ€mn)(1βˆ’k2cos2⁑(nΟ•)+ikcos⁑(nΟ•))1/n41/n+eiΟ€mn(21βˆ’k2cos2⁑(nΟ•)+2ikcos⁑(nΟ•))2/n



At first glance, this may seem pointless, since the formula has become a little more cumbersome - but don't jump to conclusions. First, there is no arcsine in it, which completely changes the mathematical meaning of the formula and allows you to look differently at the construction of a stellated polygon. Secondly, it can also be used to obtain compact formulas for special cases, for exampleit(int)1/n1+(int)2/n... Thirdly (and most interestingly), it can be creatively modified and obtained other, unexpected forms. In order for the appearance of a possible imaginary component in the radius not to cause ambiguity in the calculation, it can be immediately reduced to Cartesian coordinates by multiplying byeiΟ•... Here are examples of some of the modifications:



(βˆ’1)2/3eiΟ•(icos⁑(3Ο•)+sin2⁑(3Ο•))1/3(βˆ’1)2/3+22/3(icos⁑(3Ο•)+sin2⁑(3Ο•))2/3





eiΟ•icos⁑(2Ο•)+sin2⁑(2Ο•)ei/2+2(icos⁑(2Ο•)+sin2⁑(2Ο•))3/2





e14i(4Ο•+Ο€)2(βˆ’1)1/4cos⁑(2Ο•)+sin2⁑(2Ο•)βˆ’1βˆ’i



As you probably noticed, the rotation of the vector has ceased to be uniform - and precisely because of the appearance of the imaginary component in the radius.



Quads and stuff



Our formula has a wonderful special case - a square, the formula for which can be written as

ρ=22+2+2cos⁑(4Ο•)



or

ρ=21+1βˆ’sin2⁑(2Ο•)



(choose which one you like best).



In a slightly more developed case, you can define intermediate figures between a circle and a square through a point(k,k) on surface

ρ=21+1βˆ’(2k2βˆ’1)sin2⁑(2Ο•)k4





You can also add variation to these shapes while maintaining the condition that they pass through the point (k,k) - modulating directly the parameter itself kdepending on the angle so that when passing through the diagonal, its multiplier is equal to one. For example, substituting insteadk function k1βˆ’zcos2⁑(2Ο•), we will get an additional parameter zwith which additional bends can be adjusted. In particular, forz=1/4 you get the following:







In an even more expanded case, you can define not just a square, but a rectangle, and still in polar coordinates:

ρ=4a2b2((b2βˆ’a2)cos⁑(2Ο•)+a2+b2)(1βˆ’4a2b2ksin2⁑(2Ο•)((b2βˆ’a2)cos⁑(2Ο•)+a2+b2)2+1)



And even calculate its area (via elliptic integrals):

S=4ab(kβˆ’1)K(k)+E(k)k

Note
k (0 1) , Ο€ab 4ab.


This will allow making profiles with a transition from a circle to a rectangle with a controlled section area. Here the area is constant:





And here the area expands exponentially:





Go to Cartesian coordinates



Any formula in polar coordinates can be expressed through an equation in Cartesian coordinates, and in at least two ways - depending on which the form of the gradient on the border of the figure will change. To do this, it is enough to calculate the angle through the arctangent of the coordinates and bring the formula to a constant through the radius vector by subtracting

0=x2+y2βˆ’cos⁑(2sinβˆ’1⁑(k)+Ο€m2n)cos⁑(2sinβˆ’1⁑(kcos⁑(ntanβˆ’1⁑(x,y)))+Ο€m2n)



or division

1=x2+y2cos⁑(2sinβˆ’1⁑(kcos⁑(ntanβˆ’1⁑(x,y)))+Ο€m2n)cos⁑(2sinβˆ’1⁑(k)+Ο€m2n)



The second option is preferable because it gives straight gradients along the sides of the polygon.



Note
, (0,0) - β€” , , ( βˆ’cos⁑(2sinβˆ’1⁑(k)+Ο€m2n)sec⁑(2sinβˆ’1⁑(kcos⁑(Ο€n2))+Ο€m2n) ).



cos⁑(ntanβˆ’1⁑(x,y)) (x+iy)n+(xβˆ’iy)n2(x2+y2)n/2, A034839.


The value of the formula from the right side of the equation (in the 2nd case) will change from 0 before 1 if point (x,y) gets inside the figure, and from 1ad infinitum - if not. By choosing different functions to convert it to brightness, you can get different rasterization options. For the exponent (eβˆ’xβˆ’1 for the first and eβˆ’x for the second option) we get

or, if with saturation



Classic low pass filter can be used 11+xp, in which p- the order of the filter, which determines the degree of attenuation.



For the first option:



And for the second:



You can also use a piecewise continuous function by explicitly setting the interpolation boundaries.



In addition to rasterization as such, you can also set deformations - for example, squeeze a checkerboard into a circle:





Or even pull it over a sphere:

Formula

x=u21+|u2βˆ’v2u2+v2|



y=v1+2|u2βˆ’v2u2+v2|



z=1βˆ’12u2(1+|u2βˆ’v2u2+v2|)βˆ’12v2(1+|u2βˆ’v2u2+v2|)





Appendix: how the formula was derived



The classical style of storytelling in mathematical texts consists of the alternation of lemmas / theorems and their proofs - as if the provable statements appeared in the author's head by a revelation from above. And although there is some truth in this, more often the appearance of formulas is preceded by some research work, the description of which can give a greater understanding of their meaning than formal proof; and the fidelity of the statements, in turn, can be traced through the fidelity of the steps that led to them.



So here too - if the article began with a formula in a complex form, then its appearance would be non-obvious and counter-intuitive, and the declared properties would require additional proofs. But in the trigonometric form of recording, the history of its appearance is quite possible to trace.



1) we start with the simplest case - the task of drawing a straight line in polar coordinates. To do this, you need to solve the equationrcos⁑(Ο•)=1whose solution is obvious rβ†’sec⁑(Ο•)...





2) further, the secant argument needs to be "looped" to provide kinks in a straight line. It is at this stage that other solutions use a "dirty hack" in the form of a division remainder. It also uses sequential taking of the direct and inverse sine function -sinβˆ’1⁑(sin⁑(Ο•))





This approach allows you to perform standard mathematical operations on the resulting formula,
eg
:

βˆ‚sinβˆ’1⁑(sin⁑(Ο•))βˆ‚Ο•=cos⁑(Ο•)1βˆ’sin2⁑(Ο•)







Thanks to the same notation, you can simplify the square function in polar coordinates to a more aesthetic look, using the complex representation of trigonometric functions. In Wolfram Mathematica, this can be done using the TrigToExp and ExpToTrig functions:



The code
Sec[1/2 ArcSin[k Sin[2 \[Phi]]]]^2//TrigToExp//ExpToTrig//Sqrt[#]&//FullSimplify

↓

22+21βˆ’k2sin2⁑(2Ο•)



Thanks to the same recording, you can get smooth intermediate figures between a circle and a square using an additional multiplier kdue to which the arcsine argument falls short of one - sinβˆ’1⁑(ksin⁑(Ο•)):





And in order for the function to intersect a given point, you just need to make an equation and recalculate k:

21+1βˆ’kβ€²sin2⁑(Ο€2)=k



The code
Solve[(Sqrt[2/(1+Sqrt[1-k Sin[2 \[Phi]]^2])] /. \[Phi]->Pi/4)==x, k] /. x->k

↓

kβ€²β†’4(k2βˆ’1)k4





3) parameters n and mwere just added in a creative way and their effects were investigated experimentally, in fact.



4) Rectangle is easy to get by going to the parametric view and "stretching" the axes

x=acos⁑(t)21+1βˆ’sin2⁑(2t)



y=bsin⁑(t)21+1βˆ’sin2⁑(2t)



But after that t will no longer mean angle, now tIs just a parameter that describes a vector through its projections onto the coordinate axes. To go back to polar coordinates, you need to find the length of the vector (through the root of the sum of squares), the angle (through the arctangent of the ratio), express this angle throughΟ• and substitute the resulting expression instead t...



The code
With[{r = Sqrt[2/(1 + Sqrt[

1 - Sin[2 t]^2])]}, {Sqrt[(a r Cos[t])^2 + (b r Sin[t])^2],

ArcTan[(b r Sin[t])/(a r Cos[t])]}] // Simplify


↓

{2a2cos2⁑(t)+b2sin2⁑(t)cos2⁑(2t)+1,tanβˆ’1⁑(btan⁑(t)a)}





Solve[ArcTan[(b Tan[t])/a]==\[Phi], t]

↓

tβ†’tanβˆ’1⁑(atan⁑(Ο•)b)





Sqrt[2] Sqrt[(a^2 Cos[t]^2 + b^2 Sin[t]^2)/(1 + Sqrt[Cos[2 t]^2])]

/. t -> ArcTan[(a Tan[\[Phi]])/b] // Simplify


↓



2a2b2sec2⁑(Ο•)(a2tan2⁑(Ο•)+b2)(cos2⁑(2tanβˆ’1⁑(atan⁑(Ο•)b))+1)



To simplify such a formula is already more difficult, and this will require several stages:



  1. go to cartesian coordinates by replacing Ο•β†’tanβˆ’1⁑(x,y);
  2. go to exponential form;
  3. simplify;
  4. make a reverse replacement xβ†’cos⁑(Ο•) and yβ†’sin⁑(Ο•);
  5. go back to exponential form;
  6. simplify.


As a result, we get the following formula:



The code
Sqrt[2] Sqrt[(a^2 b^2 Sec[\[Phi]]^2) /

((1 + Sqrt[Cos[2 ArcTan[(a Tan[\[Phi]])/b]]^2])

(b^2 + a^2 Tan[\[Phi]]^2))] /. \[Phi] -> ArcTan[x, y]

// TrigToExp // Simplify

// # /. {x -> Cos[\[Phi]], y -> Sin[\[Phi]]} &

// TrigToExp // Simplify // FullSimplify


↓

2a2b2((b2βˆ’a2)cos⁑(2Ο•)+a2+b2)(1+((a2+b2)cos⁑(2Ο•)βˆ’a2+b2)2((b2βˆ’a2)cos⁑(2Ο•)+a2+b2)2)









Conclusion



As you can see, even in such a simple and banal thing as a polygon, you can find and come up with something new. And the story does not end there - the area formula for the general case remained unknown, the formula for an arbitrary, and not just regular, polygon remained unknown, and the expansion into power and trigonometric series was left without consideration. Also, probably, a similar kind of formula exists for the 3-dimensional case.



Therefore, if you are told that everything in mathematics has already been invented and there are only problems that are beyond the understanding of an ordinary person - do not believe it. There are many purely practical problems that real mathematicians are not aware of, or they are not interested in their solution due to the lack of sufficient hype around them, or because they already have a rough idea of ​​ways to achieve them for their solution. Do not be afraid to tackle problems whose solutions are not available in Wikipedia, do not be afraid to publish their solutions, and do not be afraid to read the comments under the articles about the uselessness of everything.



PS download the original document for Mathematica here .



All Articles