Polar Coordinates Animation

A couple quick programs (polarGraphs.py) to create animations of the drawing of functions in polar coordinates (for my pre-Calculus class).

Graph of the function: r = 4 cos(θ)

It can export as a movie (mp4 as above). W can also transform functions (using: polarToCartesianGraph.py ) from rectangular to polar coordinates (and back: you can choose the settings).

Coordinate transforms Cartesian to Polar and back again for r = 4 cos(θ)

A Note on using ChatGPT

This python program uses the matplotlib library, and, for the first time for me, I used ChatGPT to figure out the syntax for things like drawing arcs and arrows, and exporting animation files, instead of googling my questions. ChatGPT worked great, and significantly speeded up the process. It does make me wonder, however, that since these models are based off of what they’ve scraped from the internet, are they going to run create problems for themselves if people stop asking questions on places like stackoverflow and rely on AI instead. Although, this might just mean that the AI will tend to be just be a little bit behind the cutting edge and there will continue to be a need for question and answer forums.

Butterflies in Polar Coordinates

A butterfly outline drawn from a trigonometric function in polar coordinates.
A butterfly outline drawn from a trigonometric function in polar coordinates.

I was looking for mathematical functions I could use to shape guitar bodies, and I came across Hubpages’ user calculus-geometry‘s beautiful page on how to generate butterfly outlines using functions in polar coordinates.

The butterfly above was generated using the function:

r(θ) = 12 – sin(θ) + 2 sin(3θ) + 2 sin(5θ) – sin(7θ) + 3 cos(2θ) – 2 cos(4θ)

The code I used (using VPython) is:

from visual import *

''' the main function '''
def r(theta):
    #r = 1+cos(theta)
    
    #Archimides' sprial
    #r = 0.5*(theta) 
    
    #heart: http://jwilson.coe.uga.edu/EMT669/Essay.ideas/Heart/Hearts.html
    #r = 5*sin(theta) - sin(5*theta)
    
    #butterfly: http://calculus-geometry.hubpages.com/hub/Butterfly-Curves-in-Polar-Coordinates-on-a-Graphing-Calculator
    #r = 8-sin(theta)+2*sin(3*theta)+2*sin(5*theta)-sin(7*theta)+3*cos(2*theta)-2*cos(4*theta)
    r = 12-sin(theta)+2*sin(3*theta)+2*sin(5*theta)-sin(7*theta)+3*cos(2*theta)-2*cos(4*theta)

    return r

'''convert to rectangular coordinates'''
def xy(r, theta):
    x = r * cos(theta)
    y = r * sin(theta)
    return vector(x, y)


path = curve(color=color.green, radius=.2)


theta = 0.0

print pi, theta, r(theta) , xy(r(theta), theta)

while theta <= 2*pi:
    rate(100)
    theta += 0.01
    path.append(pos=xy(r(theta), theta))