Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'projectile_path/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopereira12 committed Jul 23, 2024
2 parents 0eda48e + 82760d4 commit ee0c0d4
Show file tree
Hide file tree
Showing 19 changed files with 21,903 additions and 0 deletions.
144 changes: 144 additions & 0 deletions projectile_path/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Other folders not for github
_not_gh_tests
_not_gh_contracts

# Added by cargo

/target


# Added by cargo
#
# already existing elements were commented out

#/target
7 changes: 7 additions & 0 deletions projectile_path/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions projectile_path/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "projectile-path"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
21 changes: 21 additions & 0 deletions projectile_path/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 whatthedev.eth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
71 changes: 71 additions & 0 deletions projectile_path/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Projectile plot generator

Simulated here is a projectile path under gravity, assuming g = 9.8 m/s^2.
- A "side-view" 2-D plot of the path is created.
- The origin is at center of the plot, the +x-axis is to the right, and the +y-axis is up. Min and max values of x and y are hard coded.


## User Inputs

*Integer* inputs:
- `num_pts` = number of points to plot along the path >=2
- `theta_0_deg` = launch angle in degrees measured from the +x-axis:
-179 <= `theta_0_deg` <= +180 degrees
- `v_0 = launch velocity magnitude: 1 <= `v_0` (in units of m/s)

After input, `theta_0_deg` and `v_0` are scaled up to be FP (fixed point) values, and `theta_0_deg` is also converted to radians, resulting in `theta_0_fp` and `v_0_fp`. The FP scale is `SCALE_FP` = 10**20.


## Cairo files

**projectile_plot.cairo** contains:
- `projectile_path`- The view function which accepts user inputs and initiates all calculations
- `position_fp_s_filler` - The function which fills an array of x-coordinates and an array of y-coordinates

**physics.cairo** contains functions for physics calculations:
- `time_in_plot_fp` - Calculates the time that the projectile is in the plot area
- `x_value_fp` - Calculates the x-coordinate of the projectile at a given time
- `y_value_fp` - Calculates the y-coordinate of the projectile at a given time

**math.cairo** contains several math functions to use with fixed point quantities:
- Square root, multiplication, division
- Distance between two points
- `cosine_6th_fp` or `cosine_8th_fp` - Taylor series approximation of cosine (to 6th order, or to 8th order), requires -pi <= angle <= pi
- `cosine_approx`
- Increases accuracy of Taylor series approximation of cosine (above) for angles in 2nd (`theta_0_deg` > 90) or 3rd (`theta_0_deg` < -90) quadrant, by (1) moving the angle to 1st or 4th quadrant (i.e. finding the mirror image of the angle, flipped across the y-axis), then (2) calling `cosine_6th_fp` or `cosine_8th_fp`, and then (3) forcing the cosine value to be negative (as it would be back in the 2nd or 3rd quadrant).
- If `theta_0_deg` = 90 or -90, then it assigns the exact value, 0, to the cosine (rather than approximating).
- `sine_approx` - Finds the sine of an angle, using a trig identity and the cosine of the angle.

**constants.cairo** contains:
- FP math constants
- Other math constants
- Physical parameters (except those that are user inputs)
- Plot parameters (except those that are user inputs)


## Tests

**test_projectile_plot.py**
- Contains input parameters which are fed into both Cairo and Python calculations
- Contains other constants and parameters (that should match those in **constants.cairo**) for Python calculations
- Contains Python calculations of projectile path coordinates, to compare to same Cairo calculations done by calling `projectile_path` function from **projectile_plot.cairo**, using same input parameters
- Dumps calculated values to .json files (one each for cairo and python calculations) to be used by Jupyter notebook, **test_projectile_plot.ipynb**
- Prints for comparison the values (as FP) from the coordinate arrays found with Cairo and Python
- To run: `pytest -s tests/test_projectile_plot.py`


**test_projectile_plot.ipynb**
- Jupyter notebook which plots two projectile paths:
- Array calculated in Cairo by **projectile_plot.cairo**
- Array calculated in Python by **test_projectile_plot.py**
- Gets data from .json files created in **test_projectile_plot.py**
- To run:
- Install [Jupyter Notebook](https://jupyter.org/install)
- `jupyter notebook`, follow instructions to open notebook in browser
- Open file **test_projectile_plot.ipynb**

(An additional Jupyter notebook, **prototype_projectile_plot.ipynb**, was used to first prototype all calculations that were done in the Cairo files. The Python calculations here were then duplicated in **test_projectile_plot.ipynb**.)

## License

This repository is licensed under the MIT license.
39 changes: 39 additions & 0 deletions projectile_path/artifacts/projectile_plot_abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"inputs": [
{
"name": "num_pts",
"type": "felt"
},
{
"name": "theta_0_deg",
"type": "felt"
},
{
"name": "v_0",
"type": "felt"
}
],
"name": "projectile_path",
"outputs": [
{
"name": "x_fp_s_len",
"type": "felt"
},
{
"name": "x_fp_s",
"type": "felt*"
},
{
"name": "y_fp_s_len",
"type": "felt"
},
{
"name": "y_fp_s",
"type": "felt*"
}
],
"stateMutability": "view",
"type": "function"
}
]
Loading

0 comments on commit ee0c0d4

Please sign in to comment.