
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/03-projectiles_and_scaling/3.5-plot_projectile_impact_angle.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_03-projectiles_and_scaling_3.5-plot_projectile_impact_angle.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_03-projectiles_and_scaling_3.5-plot_projectile_impact_angle.py:


Plot random projectile impact angles
====================================

.. rubric:: By David Minton and Dennise Valadez

This example demonstrates how to generate and visualize random impact angles for projectiles using cratermaker.

.. GENERATED FROM PYTHON SOURCE LINES 10-47



.. image-sg:: /auto_examples/03-projectiles_and_scaling/images/sphx_glr_3.5-plot_projectile_impact_angle_001.png
   :alt: Impact Angle Distribution
   :srcset: /auto_examples/03-projectiles_and_scaling/images/sphx_glr_3.5-plot_projectile_impact_angle_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from cratermaker import Projectile

    # Sample data generation
    proj = Projectile(mean_velocity=5000, density=3000)
    size = 10000
    angles = np.array([proj.new_projectile().angle for _ in range(size)])

    # Number of bins
    bins = 50
    observed_counts, bins_ang = np.histogram(angles, bins=bins, range=(0.0, 90.0))

    # Expected distribution
    uniform_dist = np.linspace(0, 1, size)
    transformed_angles = np.rad2deg(np.arcsin(np.sqrt(uniform_dist)))
    expected_counts, _ = np.histogram(transformed_angles, bins=bins, range=(0.0, 90.0))

    # Plotting distribution
    fig, ax = plt.subplots(figsize=(8, 4))
    ax.bar(
        bins_ang[:-1],
        observed_counts,
        width=np.diff(bins_ang),
        align="edge",
        label="Observed",
        alpha=0.5,
    )
    ax.plot(bins_ang[:-1], expected_counts, label="Expected", color="red")
    ax.set_xlabel("Impact Angle (deg)")
    ax.set_ylabel("Count")
    ax.legend()
    ax.set_title("Impact Angle Distribution")
    plt.tight_layout()
    plt.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 3.031 seconds)


.. _sphx_glr_download_auto_examples_03-projectiles_and_scaling_3.5-plot_projectile_impact_angle.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 3.5-plot_projectile_impact_angle.ipynb <3.5-plot_projectile_impact_angle.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 3.5-plot_projectile_impact_angle.py <3.5-plot_projectile_impact_angle.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 3.5-plot_projectile_impact_angle.zip <3.5-plot_projectile_impact_angle.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
