1

I have a angle 'q' defined by the following equation:

q = 150*(t**2)

I'm trying to plot a graph that contains the variation of q based on the time, but the angle goes further than 2pi if I try to plot it for more than 1 cycle of rotation, I need to "reset" the angle to 0 when it reaches the value of (2pi) as the system returns to it's start at the end of every cycle, does anyone have any clue of how can I do that on python?

Image containing the angle "q" that I'm talking about

my plotting code is:

import numpy as np
import matplotlib,pyplot as plt
t = np.arange(0,7*0.06097,0.001) # time for 1 cycle is 0.06097s. I'm plotting for 7 cycles.
q = 150*(t**2)
plt.plot(t,q)

This is the graph that I've managed to plot, but as you can see, it goes further than the maximum value of (2pi rad or aprox 6.28 rad)

1 Answers1

0

Use np.fmod(x, 2*np.pi) to get a value modulo 2pi.

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0,7*0.06097,0.001) # time for 1 cycle is 0.06097s. I'm plotting for 7 cycles.
q = np.fmod(150*(t**2), 2*np.pi)
plt.plot(t,q)
plt.show()

Result of plt.plot

Stef
  • 13,242
  • 2
  • 17
  • 28