simetri.geometry.sine
Sinusoidal wave generator
1"""Sinusoidal wave generator""" 2 3import numpy as np 4 5from ..graphics.shape import Shape 6from ..graphics.all_enums import Types 7 8 9class SineWave(Shape): 10 """Sinusoidal wave generator 11 12 Args: 13 period (float, optional): Period of the sine wave. Defaults to 40. 14 amplitude (float, optional): Amplitude of the sine wave. Defaults to 20. 15 duration (float, optional): Duration of the sine wave. Defaults to 1. 16 n_points (int, optional): Sampling rate. Defaults to 100. 17 phase_angle (float, optional): Phase angle of the sine wave. Defaults to 0. 18 damping (float, optional): Damping coefficient. .001-.005 is usual. Defaults to 0. 19 rot_angle (float, optional): Rotation angle of the sine wave.. Defaults to 0. 20 xform_matrix (ndarray, optional): Transformation matrix. Defaults to None. 21 22 Returns: 23 Shape: _description_ 24 """ 25 26 def __init__( 27 self, 28 period: float = 40, 29 amplitude: float = 20, 30 duration: float = 40, 31 n_points: int = 100, 32 phase_angle: float = 0, 33 damping: float = 0, 34 rot_angle: float = 0, 35 xform_matrix: 'ndarray' = None, 36 **kwargs, 37 )-> Shape: 38 phase = phase_angle 39 freq = 1 / period 40 n_cycles = duration / period 41 x = np.linspace(0, duration, int(n_points * n_cycles)) 42 y = amplitude * np.sin(2 * np.pi * freq * x + phase) 43 if damping: 44 y *= np.exp(-damping * x) 45 vertices = np.column_stack((x, y)).tolist() 46 super().__init__(vertices, xform_matrix=xform_matrix, **kwargs) 47 self.subtype = Types.SINE_WAVE 48 self.period = period, 49 self.amplitude = amplitude, 50 self.duration = duration, 51 self.n_points = n_points, 52 self.phase = phase, 53 self.damping = damping, 54 self.rot_angle = rot_angle, 55 56 57 def copy_(self): 58 """_description_ 59 60 Returns: 61 SineWave: _description_ 62 """ 63 return SineWave( 64 self.period, 65 self.amplitude, 66 self.duration, 67 self.n_points, 68 self.phase, 69 self.damping, 70 self.rot_angle, 71 self.xform_matrix, 72 **self.kwargs, 73 )
10class SineWave(Shape): 11 """Sinusoidal wave generator 12 13 Args: 14 period (float, optional): Period of the sine wave. Defaults to 40. 15 amplitude (float, optional): Amplitude of the sine wave. Defaults to 20. 16 duration (float, optional): Duration of the sine wave. Defaults to 1. 17 n_points (int, optional): Sampling rate. Defaults to 100. 18 phase_angle (float, optional): Phase angle of the sine wave. Defaults to 0. 19 damping (float, optional): Damping coefficient. .001-.005 is usual. Defaults to 0. 20 rot_angle (float, optional): Rotation angle of the sine wave.. Defaults to 0. 21 xform_matrix (ndarray, optional): Transformation matrix. Defaults to None. 22 23 Returns: 24 Shape: _description_ 25 """ 26 27 def __init__( 28 self, 29 period: float = 40, 30 amplitude: float = 20, 31 duration: float = 40, 32 n_points: int = 100, 33 phase_angle: float = 0, 34 damping: float = 0, 35 rot_angle: float = 0, 36 xform_matrix: 'ndarray' = None, 37 **kwargs, 38 )-> Shape: 39 phase = phase_angle 40 freq = 1 / period 41 n_cycles = duration / period 42 x = np.linspace(0, duration, int(n_points * n_cycles)) 43 y = amplitude * np.sin(2 * np.pi * freq * x + phase) 44 if damping: 45 y *= np.exp(-damping * x) 46 vertices = np.column_stack((x, y)).tolist() 47 super().__init__(vertices, xform_matrix=xform_matrix, **kwargs) 48 self.subtype = Types.SINE_WAVE 49 self.period = period, 50 self.amplitude = amplitude, 51 self.duration = duration, 52 self.n_points = n_points, 53 self.phase = phase, 54 self.damping = damping, 55 self.rot_angle = rot_angle, 56 57 58 def copy_(self): 59 """_description_ 60 61 Returns: 62 SineWave: _description_ 63 """ 64 return SineWave( 65 self.period, 66 self.amplitude, 67 self.duration, 68 self.n_points, 69 self.phase, 70 self.damping, 71 self.rot_angle, 72 self.xform_matrix, 73 **self.kwargs, 74 )
Sinusoidal wave generator
Arguments:
- period (float, optional): Period of the sine wave. Defaults to 40.
- amplitude (float, optional): Amplitude of the sine wave. Defaults to 20.
- duration (float, optional): Duration of the sine wave. Defaults to 1.
- n_points (int, optional): Sampling rate. Defaults to 100.
- phase_angle (float, optional): Phase angle of the sine wave. Defaults to 0.
- damping (float, optional): Damping coefficient. .001-.005 is usual. Defaults to 0.
- rot_angle (float, optional): Rotation angle of the sine wave.. Defaults to 0.
- xform_matrix (ndarray, optional): Transformation matrix. Defaults to None.
Returns:
Shape: _description_
SineWave( period: float = 40, amplitude: float = 20, duration: float = 40, n_points: int = 100, phase_angle: float = 0, damping: float = 0, rot_angle: float = 0, xform_matrix: 'ndarray' = None, **kwargs)
27 def __init__( 28 self, 29 period: float = 40, 30 amplitude: float = 20, 31 duration: float = 40, 32 n_points: int = 100, 33 phase_angle: float = 0, 34 damping: float = 0, 35 rot_angle: float = 0, 36 xform_matrix: 'ndarray' = None, 37 **kwargs, 38 )-> Shape: 39 phase = phase_angle 40 freq = 1 / period 41 n_cycles = duration / period 42 x = np.linspace(0, duration, int(n_points * n_cycles)) 43 y = amplitude * np.sin(2 * np.pi * freq * x + phase) 44 if damping: 45 y *= np.exp(-damping * x) 46 vertices = np.column_stack((x, y)).tolist() 47 super().__init__(vertices, xform_matrix=xform_matrix, **kwargs) 48 self.subtype = Types.SINE_WAVE 49 self.period = period, 50 self.amplitude = amplitude, 51 self.duration = duration, 52 self.n_points = n_points, 53 self.phase = phase, 54 self.damping = damping, 55 self.rot_angle = rot_angle,
Initialize a Shape object.
Arguments:
- points (Sequence[Point], optional): The points that make up the shape.
- closed (bool, optional): Whether the shape is closed. Defaults to False.
- xform_matrix (np.array, optional): The transformation matrix. Defaults to None.
- **kwargs (dict): Additional attributes for the shape.
Raises:
- ValueError: If the provided subtype is not valid.
def
copy_(self):
58 def copy_(self): 59 """_description_ 60 61 Returns: 62 SineWave: _description_ 63 """ 64 return SineWave( 65 self.period, 66 self.amplitude, 67 self.duration, 68 self.n_points, 69 self.phase, 70 self.damping, 71 self.rot_angle, 72 self.xform_matrix, 73 **self.kwargs, 74 )
_description_
Returns:
SineWave: _description_