{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Warping by Vectors {#warp_by_vectors_example}\n\nThis example applies the `warp_by_vector` filter to a sphere mesh that\nhas 3D displacement vectors defined at each node.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We first compare the unwarped sphere to the warped sphere.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from itertools import product\n\nimport pyvista as pv\nfrom pyvista import examples\n\nsphere = examples.load_sphere_vectors()\nwarped = sphere.warp_by_vector()\n\np = pv.Plotter(shape=(1, 2))\np.subplot(0, 0)\np.add_text(\"Before warp\")\np.add_mesh(sphere, color='white')\np.subplot(0, 1)\np.add_text(\"After warp\")\np.add_mesh(warped, color='white')\np.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We then use several values for the scale factor applied to the warp\noperation. Applying a warping factor that is too high can often lead to\nunrealistic results.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "warp_factors = [0, 1.5, 3.5, 5.5]\np = pv.Plotter(shape=(2, 2))\nfor i, j in product(range(2), repeat=2):\n idx = 2 * i + j\n p.subplot(i, j)\n p.add_mesh(sphere.warp_by_vector(factor=warp_factors[idx]))\n p.add_text(f'factor={warp_factors[idx]}')\np.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }