derek-thomas
		
	commited on
		
		
					Commit 
							
							·
						
						3dc2c17
	
1
								Parent(s):
							
							7238c11
								
Added some comments, added help strings, made disc orientation work as expected.
Browse files- disc_golf_simulator.py +27 -11
- utilities/visualize.py +1 -1
    	
        disc_golf_simulator.py
    CHANGED
    
    | @@ -1,8 +1,10 @@ | |
|  | |
| 1 | 
             
            from logging import getLogger
         | 
| 2 | 
             
            from pathlib import Path
         | 
| 3 |  | 
| 4 | 
             
            import numpy as np
         | 
| 5 | 
             
            import streamlit as st
         | 
|  | |
| 6 | 
             
            from shotshaper.projectile import DiscGolfDisc
         | 
| 7 | 
             
            from utilities.visualize import get_plot, get_subplots, stl_meshes, visualize_disc
         | 
| 8 |  | 
| @@ -52,18 +54,27 @@ def main(): | |
| 52 | 
             
                    # Create the sliders with the default values
         | 
| 53 | 
             
                    with st.container():
         | 
| 54 | 
             
                        st.sidebar.markdown("### Disc Orientation")
         | 
| 55 | 
            -
                        nose = st.sidebar.slider("Nose Angle (deg) | Up/Down", min_value | 
|  | |
| 56 | 
             
                                                 step=0.1)
         | 
| 57 | 
            -
                        roll = st.sidebar.slider("Roll Angle (deg) |  | 
|  | |
|  | |
|  | |
| 58 | 
             
                                                 value=default_roll,
         | 
| 59 | 
             
                                                 step=0.1)
         | 
| 60 | 
             
                    with st.sidebar.container():
         | 
| 61 | 
             
                        st.sidebar.markdown("### Throwing Properties")
         | 
| 62 | 
             
                        U = st.sidebar.slider("Throwing Velocity (m/s)", min_value=0.0, max_value=40.0, value=default_U, step=0.1,
         | 
| 63 | 
            -
                                              help=' | 
| 64 | 
            -
             | 
| 65 | 
            -
                         | 
|  | |
|  | |
|  | |
|  | |
| 66 | 
             
                        pitch = st.sidebar.slider("Pitch Angle (deg) | Release angle", min_value=0.0, max_value=90.0,
         | 
|  | |
| 67 | 
             
                                                  value=default_pitch,
         | 
| 68 | 
             
                                                  step=0.1)
         | 
| 69 |  | 
| @@ -71,13 +82,18 @@ def main(): | |
| 71 | 
             
                        pos = np.array((0, 0, z0))
         | 
| 72 | 
             
                        disc_dict = DiscGolfDisc(disc_name)
         | 
| 73 |  | 
| 74 | 
            -
                        stl_mesh = stl_meshes[disc_name]
         | 
| 75 | 
             
                        fig = visualize_disc(stl_mesh, nose=nose, roll=roll)
         | 
| 76 |  | 
| 77 | 
            -
                        st.markdown(""" | 
|  | |
|  | |
|  | |
| 78 | 
             
                        st.plotly_chart(fig)
         | 
| 79 | 
             
                    with st.spinner(text="Calculating Flight Path..."):
         | 
| 80 | 
            -
                        st.markdown(""" | 
|  | |
|  | |
| 81 | 
             
                        shot = disc_dict.shoot(speed=U, omega=omega, pitch=pitch,
         | 
| 82 | 
             
                                               position=pos, nose_angle=nose, roll_angle=roll)
         | 
| 83 |  | 
| @@ -88,14 +104,13 @@ def main(): | |
| 88 | 
             
                        # Reversed x and y to mimic a throw
         | 
| 89 | 
             
                        fig = get_plot(x_new, y_new, z)
         | 
| 90 | 
             
                        st.plotly_chart(fig, True)
         | 
| 91 | 
            -
             | 
| 92 | 
             
                        st.markdown(
         | 
| 93 | 
             
                                f"""
         | 
| 94 | 
             
                        **Arrows in Blue** show you where your *s-turn* is.
         | 
| 95 |  | 
| 96 | 
             
                        **Arrows in Red** show you your *max height* and *lateral deviance*.
         | 
| 97 |  | 
| 98 | 
            -
                        Hit Play to watch your animated throw.
         | 
| 99 |  | 
| 100 | 
             
                        | Metric       | Value  |
         | 
| 101 | 
             
                        |--------------|--------|
         | 
| @@ -109,7 +124,8 @@ def main(): | |
| 109 |  | 
| 110 | 
             
                        arc, alphas, betas, lifts, drags, moms, rolls = disc_dict.post_process(shot, omega)
         | 
| 111 | 
             
                        fig = get_subplots(arc, alphas, lifts, drags, moms, rolls, shot.velocity)
         | 
| 112 | 
            -
                        st. | 
|  | |
| 113 |  | 
| 114 | 
             
                with tab2:
         | 
| 115 | 
             
                    st.markdown(faq)
         | 
|  | |
| 1 | 
            +
            from copy import deepcopy
         | 
| 2 | 
             
            from logging import getLogger
         | 
| 3 | 
             
            from pathlib import Path
         | 
| 4 |  | 
| 5 | 
             
            import numpy as np
         | 
| 6 | 
             
            import streamlit as st
         | 
| 7 | 
            +
             | 
| 8 | 
             
            from shotshaper.projectile import DiscGolfDisc
         | 
| 9 | 
             
            from utilities.visualize import get_plot, get_subplots, stl_meshes, visualize_disc
         | 
| 10 |  | 
|  | |
| 54 | 
             
                    # Create the sliders with the default values
         | 
| 55 | 
             
                    with st.container():
         | 
| 56 | 
             
                        st.sidebar.markdown("### Disc Orientation")
         | 
| 57 | 
            +
                        nose = st.sidebar.slider("Nose Angle (deg) | Up/Down", min_value=-45.0, max_value=90.0, value=default_nose,
         | 
| 58 | 
            +
                                                 help='0 is the disc pointing to the horizon\n90 is the disc pointing to the sky.',
         | 
| 59 | 
             
                                                 step=0.1)
         | 
| 60 | 
            +
                        roll = st.sidebar.slider("Roll Angle (deg) | Anhyzer/Hyzer", min_value=-90.0, max_value=90.0,
         | 
| 61 | 
            +
                                                 help='-90 the disc is very anhyzer, '
         | 
| 62 | 
            +
                                                      '0 is the disc flat on the table, '
         | 
| 63 | 
            +
                                                      '90 the disc is very hyzer',
         | 
| 64 | 
             
                                                 value=default_roll,
         | 
| 65 | 
             
                                                 step=0.1)
         | 
| 66 | 
             
                    with st.sidebar.container():
         | 
| 67 | 
             
                        st.sidebar.markdown("### Throwing Properties")
         | 
| 68 | 
             
                        U = st.sidebar.slider("Throwing Velocity (m/s)", min_value=0.0, max_value=40.0, value=default_U, step=0.1,
         | 
| 69 | 
            +
                                              help='20m/s is a begginer\'s throw. '
         | 
| 70 | 
            +
                                                   'The fastest throw on record is ~40m/s by Simon Lizotte')
         | 
| 71 | 
            +
                        omega = st.sidebar.slider("Omega (revolutions/s)", min_value=0.0, max_value=200.0, value=default_omega,
         | 
| 72 | 
            +
                                                  step=0.1,
         | 
| 73 | 
            +
                                                  help='How much spin do you have?')
         | 
| 74 | 
            +
                        z0 = st.sidebar.slider("Release Height (m)", min_value=0.0, max_value=2.0, value=default_z0, step=0.1,
         | 
| 75 | 
            +
                                               help='How high is your arm when throwing?')
         | 
| 76 | 
             
                        pitch = st.sidebar.slider("Pitch Angle (deg) | Release angle", min_value=0.0, max_value=90.0,
         | 
| 77 | 
            +
                                                  help='0 = flat, 90 = aiming straight up',
         | 
| 78 | 
             
                                                  value=default_pitch,
         | 
| 79 | 
             
                                                  step=0.1)
         | 
| 80 |  | 
|  | |
| 82 | 
             
                        pos = np.array((0, 0, z0))
         | 
| 83 | 
             
                        disc_dict = DiscGolfDisc(disc_name)
         | 
| 84 |  | 
| 85 | 
            +
                        stl_mesh = deepcopy(stl_meshes[disc_name])
         | 
| 86 | 
             
                        fig = visualize_disc(stl_mesh, nose=nose, roll=roll)
         | 
| 87 |  | 
| 88 | 
            +
                        st.markdown("""
         | 
| 89 | 
            +
                        ## Disc Orientation
         | 
| 90 | 
            +
                        This is what your disc should look like after you release. The `Nose Angle` and `Roll Angle` 
         | 
| 91 | 
            +
                        sidebar sliders control this.""")
         | 
| 92 | 
             
                        st.plotly_chart(fig)
         | 
| 93 | 
             
                    with st.spinner(text="Calculating Flight Path..."):
         | 
| 94 | 
            +
                        st.markdown("""
         | 
| 95 | 
            +
                        ## Flight Path
         | 
| 96 | 
            +
                        Based on the sliders to the left, this will determine what your throw will look like.""")
         | 
| 97 | 
             
                        shot = disc_dict.shoot(speed=U, omega=omega, pitch=pitch,
         | 
| 98 | 
             
                                               position=pos, nose_angle=nose, roll_angle=roll)
         | 
| 99 |  | 
|  | |
| 104 | 
             
                        # Reversed x and y to mimic a throw
         | 
| 105 | 
             
                        fig = get_plot(x_new, y_new, z)
         | 
| 106 | 
             
                        st.plotly_chart(fig, True)
         | 
|  | |
| 107 | 
             
                        st.markdown(
         | 
| 108 | 
             
                                f"""
         | 
| 109 | 
             
                        **Arrows in Blue** show you where your *s-turn* is.
         | 
| 110 |  | 
| 111 | 
             
                        **Arrows in Red** show you your *max height* and *lateral deviance*.
         | 
| 112 |  | 
| 113 | 
            +
                        Hit `Play` to watch your animated throw.
         | 
| 114 |  | 
| 115 | 
             
                        | Metric       | Value  |
         | 
| 116 | 
             
                        |--------------|--------|
         | 
|  | |
| 124 |  | 
| 125 | 
             
                        arc, alphas, betas, lifts, drags, moms, rolls = disc_dict.post_process(shot, omega)
         | 
| 126 | 
             
                        fig = get_subplots(arc, alphas, lifts, drags, moms, rolls, shot.velocity)
         | 
| 127 | 
            +
                        with st.expander("Optional Charts for science-y people"):
         | 
| 128 | 
            +
                            st.plotly_chart(fig, True)
         | 
| 129 |  | 
| 130 | 
             
                with tab2:
         | 
| 131 | 
             
                    st.markdown(faq)
         | 
    	
        utilities/visualize.py
    CHANGED
    
    | @@ -95,7 +95,7 @@ def get_plot(x, y, z): | |
| 95 | 
             
                        )
         | 
| 96 |  | 
| 97 | 
             
                # Create figure with subplots
         | 
| 98 | 
            -
                fig = sp.make_subplots(rows=2, cols=2, subplot_titles=("Flight Path", "Height", "Lateral Deviance"),
         | 
| 99 | 
             
                                       specs=[[{"rowspan": 2}, {}], [None, {}]], row_heights=[0.5, 0.5])
         | 
| 100 |  | 
| 101 | 
             
                # Add traces to the main plot
         | 
|  | |
| 95 | 
             
                        )
         | 
| 96 |  | 
| 97 | 
             
                # Create figure with subplots
         | 
| 98 | 
            +
                fig = sp.make_subplots(rows=2, cols=2, subplot_titles=("Flight Path", "Height (over time)", "Lateral Deviance (left and right motion)"),
         | 
| 99 | 
             
                                       specs=[[{"rowspan": 2}, {}], [None, {}]], row_heights=[0.5, 0.5])
         | 
| 100 |  | 
| 101 | 
             
                # Add traces to the main plot
         | 
