A Python program that demonstrates how to compute parametric functions given two turning points.
- In the current version of this test program, the following parametric functions are computed.
- Sine function of the form,
$f(t) = a \cdot \sin(w \cdot (t - p)) + c$ , given two turning points. - Cubic polynomial of the form,
$f(x) = a \cdot x^3 + b \cdot x^2 + c \cdot x + d$ , given two turing points.
- Sine function of the form,
- The program also shows how to find solutions for the coefficients of a cubic polynomial, given two turning points.
The functions cubic_segment and sin_segment are the parametric functions demonstrated in this program.
Both functions take two input vector parameters that serve as the parametric points through which the functions pass.
- Parameters:
- Vector for point 1.
$...\vec{p_0} ( x_0, y_0 )$ - Vector for point 2.
$...\vec{p_1} ( x_1, y_1 )$
- Vector for point 1.
- Return:
- [ Array of x values, Array of y values ]
$...\vec{Y} = f ( \vec{X} )$
- [ Array of x values, Array of y values ]
The functions may be tested by setting up input vectors that represent turning points through which the function passes.
# Test parametric cubic polynomial
v0 = [ 0.2 , 0.2 ]
v1 = [ 0.8 , 0.8 ]
data = cubic_segment ( v0, v1 )# Test parametric sine function.
v0 = [ 1.0 , -0.75 ]
v1 = [ 4.0 , 0.5 ]
data = sin_segment ( v0, v1 )Output data is returned as two arrays, one for the function domain (independent variable), and range (dependent variable).
- In terms of notation, we'll express the domain for linear algebraic functions as
$x$ , and for trigonometric functions, we'll express it as$t$ . - In the example below, we will use the data to plot the computed parametric functions.
- See the implementation of the
plot_functionfor the details of the plots shown below.
# Test parametric cubic polynomial function.
v0 = [ 0.2 , 0.2 ]
v1 = [ 0.8 , 0.8 ]
data = cubic_segment ( v0, v1 )
# Plot the computed function.
lim_x = [ 0.0, 1.0 ]
lim_y = [ 0.0, 1.0 ]
plot_function (
data,
[ v0, v1 ],
[ lim_x, lim_y ],
'Parametric Cubic Polynomial', 'f(x) = a·x³ + b·x² + c·x + d'
) # Test parametric sine function.
v0 = [ 1.0 , -0.75 ]
v1 = [ 4.0 , 0.5 ]
data = sin_segment ( v0, v1 )
# Plot the computed function.
lim_x = [ 0, 2*PI ]
lim_y = [ -1, 1 ]
plot_function (
data,
[ v0, v1 ],
[ lim_x, lim_y ],
'Parametric Sine Function',
'f(t) = a·sin( w·(t - p) ) + c'
) -
Note:
- Parameters computed using symbolic solver from the Python
sympypackage. - In the code, the
solve_cubic_coefficients()function implements thesympysymbolic solution to compute the coeficients.
- Parameters computed using symbolic solver from the Python
-
Given:
- System of equations to solve:
- Constraints:
- Coefficient (Paramter) Solutions:
-
Note:
- Parameters computed intuitively. No need to formally solve the system of equations.
-
Given:
- System of equations to solve:
- Constraints:
- Paramter Solutions:
- Python 3.x
-
Clone the repository:
git clone https://github.com/your-username/your-repo.git
-
Navigate to the project directory:
cd your-repo -
Create and activate the virtual environment using the provided batch files:
- To create the virtual environment and activate it, run:
venv_create.bat
- If you need to activate the virtual environment later, run:
venv_activate.bat
- To deactivate the virtual environment, run:
venv_deactivate.bat
- To delete the virtual environment, run:
venv_delete.bat
- To create the virtual environment and activate it, run:
-
Install the required packages:
venv_install_requirements.bat
-
To save the current list of installed packages to
venv_requirements.txt, run:venv_save_requirements.bat
Contributions are welcome! Please follow the contribution guidelines.
- Fork the project.
- Create your feature branch (git checkout -b feature/AmazingFeature).
- Commit your changes (git commit -m 'Add some AmazingFeature').
- Push to the branch (git push origin feature/AmazingFeature).
- Open a pull request.
Distributed under the MIT License. See LICENSE for more information.
- Twitter: @rohingosling
- Project Link: https://github.com/rohingosling/parametric-functions/tree/main
- N/A

