
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/02_rotated_geometry.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_02_rotated_geometry.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_02_rotated_geometry.py:


Rotated Geometry
================

Rotation of a block model geometry is a common operation in geoscience applications.
By rotating the geometry, we can align it with geological features.
Rotation is typically specified in degrees from the cardinal orthonormal axes (x, y, z).

.. GENERATED FROM PYTHON SOURCE LINES 10-17

.. code-block:: Python


    import pyvista as pv
    from parq_blockmodel import RegularGeometry
    from parq_blockmodel.utils import angles_to_axes

    # sphinx_gallery_thumbnail_number = -1








.. GENERATED FROM PYTHON SOURCE LINES 18-21

Create Two Geometries: Unrotated and Rotated
--------------------------------------------
We first create an unrotated geometry, then rotate the world axes by 30 degrees.

.. GENERATED FROM PYTHON SOURCE LINES 21-38

.. code-block:: Python


    geom_unrotated = RegularGeometry(
        corner=(0.0, 0.0, 0.0),
        block_size=(1.0, 1.0, 1.0),
        shape=(2, 2, 2),
    )

    axis_u, axis_v, axis_w = angles_to_axes(axis_azimuth=30, axis_dip=0, axis_plunge=0)
    geom_rotated = RegularGeometry(
        corner=(0.0, 0.0, 0.0),
        block_size=(1.0, 1.0, 1.0),
        shape=(2, 2, 2),
        axis_u=axis_u,
        axis_v=axis_v,
        axis_w=axis_w,
    )








.. GENERATED FROM PYTHON SOURCE LINES 39-40

Visualise Unrotated then Rotated in 3D

.. GENERATED FROM PYTHON SOURCE LINES 40-67

.. code-block:: Python

    isometric_view = [(6, 5, 3),  # camera position
                      (1, 1, 1),  # focal point (center of the grid)
                      (0, 0, 1),  # view up direction
                      ]

    plotter = pv.Plotter()
    edges = geom_unrotated.to_pyvista().extract_all_edges()
    plotter.add_mesh(edges, color="black", line_width=1)
    plotter.show_axes()
    plotter.camera_position = isometric_view
    plotter.show(title="Unrotated Regular Geometry", window_size=(800, 600))

    plotter = pv.Plotter()
    edges = geom_rotated.to_pyvista().extract_all_edges()
    plotter.add_mesh(edges, color="black", line_width=1)
    plotter.show_axes()
    plotter.camera_position = isometric_view
    plotter.show(title="Rotated Regular Geometry (World Frame)", window_size=(800, 600))

    # Optional: local frame plot (axis-aligned, no rotation)
    plotter = pv.Plotter()
    edges = geom_rotated.to_pyvista(frame="local").extract_all_edges()
    plotter.add_mesh(edges, color="black", line_width=1)
    plotter.show_axes()
    plotter.camera_position = isometric_view
    plotter.show(title="Rotated Geometry in Local Frame", window_size=(800, 600))




.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /auto_examples/images/sphx_glr_02_rotated_geometry_001.png
          :alt: 02 rotated geometry
          :srcset: /auto_examples/images/sphx_glr_02_rotated_geometry_001.png
          :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/images/sphx_glr_02_rotated_geometry_002.png
          :alt: 02 rotated geometry
          :srcset: /auto_examples/images/sphx_glr_02_rotated_geometry_002.png
          :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/images/sphx_glr_02_rotated_geometry_003.png
          :alt: 02 rotated geometry
          :srcset: /auto_examples/images/sphx_glr_02_rotated_geometry_003.png
          :class: sphx-glr-multi-img





.. GENERATED FROM PYTHON SOURCE LINES 68-70

Visualise in 2D
Slice at z=0.5 to intersect the first layer of cells

.. GENERATED FROM PYTHON SOURCE LINES 70-91

.. code-block:: Python

    slice_2d = geom_rotated.to_pyvista().slice(normal='z', origin=(0, 0, 0.5))
    edges_2d = slice_2d.extract_all_edges()
    points = edges_2d.points
    labels = [f"({x:.1f}, {y:.1f})" for x, y, _ in points]
    centroids_mesh = slice_2d.cell_centers()
    centroids = centroids_mesh.points
    labels_centroids_2d = [f"C({x:.1f}, {y:.1f})" for x, y, _ in centroids]
    plotter = pv.Plotter()
    plotter.add_mesh(edges_2d, color="black", show_edges=True)
    plotter.add_point_labels(points, labels, font_size=12, point_color="red", point_size=10)
    plotter.add_points(centroids, color="blue", point_size=15, render_points_as_spheres=True)
    plotter.add_point_labels(centroids,
                             labels_centroids_2d,
                             font_size=12,
                             point_color="blue",
                             point_size=0,  # Hide label points
                             always_visible=True,
                             render_points_as_spheres=False)
    plotter.show_axes()
    plotter.view_xy()
    plotter.show(title="2D Slice with Corner and Centroid Coordinates", window_size=(600, 600))



.. image-sg:: /auto_examples/images/sphx_glr_02_rotated_geometry_004.png
   :alt: 02 rotated geometry
   :srcset: /auto_examples/images/sphx_glr_02_rotated_geometry_004.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_auto_examples_02_rotated_geometry.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: 02_rotated_geometry.ipynb <02_rotated_geometry.ipynb>`

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

      :download:`Download Python source code: 02_rotated_geometry.py <02_rotated_geometry.py>`

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

      :download:`Download zipped: 02_rotated_geometry.zip <02_rotated_geometry.zip>`


.. only:: html

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

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