|
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"import vispy, vispy.app\n", |
|
"vispy.app.use_app('ipynb_webgl')\n", |
|
"import plato\n", |
|
"import plato.draw.vispy as draw\n", |
|
"import itertools\n", |
|
"import rowan\n", |
|
"import numpy as np\n", |
|
"import IPython" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"def example_vector_field(N):\n", |
|
" xs = np.linspace(-N/2, N/2, N)\n", |
|
" positions = np.array(list(itertools.product(xs, xs, xs)), dtype=np.float32)\n", |
|
" positions = positions.reshape((-1, 3))\n", |
|
"\n", |
|
" thetas = np.arctan2(positions[:, 1], positions[:, 0])\n", |
|
" circle = np.array([-np.sin(thetas), np.cos(thetas), np.zeros_like(thetas)]).T\n", |
|
"\n", |
|
" rotated = np.cross(positions, circle)\n", |
|
" rotated /= np.linalg.norm(rotated, axis=-1, keepdims=True)\n", |
|
" rotated[np.logical_not(np.all(np.isfinite(rotated), axis=-1))] = (1, 0, 0)\n", |
|
"\n", |
|
" return positions, rotated" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"features = dict(ambient_light=.4)\n", |
|
"(positions, units) = example_vector_field(5)\n", |
|
"\n", |
|
"normalized_z = positions[:, 2].copy()\n", |
|
"normalized_z -= np.min(normalized_z)\n", |
|
"normalized_z /= np.max(normalized_z)\n", |
|
"\n", |
|
"colors = plato.cmap.cubehelix(normalized_z, h=1.4)\n", |
|
"colors[:, :3] = .5*(colors[:, :3] +\n", |
|
" plato.cmap.cubeellipse(np.arctan2(positions[:, 1], positions[:, 0])))\n", |
|
"\n", |
|
"orientations = rowan.vector_vector_rotation([(1, 0, 0)], units)\n", |
|
"prim = draw.Ellipsoids(\n", |
|
" positions=positions, orientations=orientations, colors=colors,\n", |
|
" a=.5, b=.125, c=.125)\n", |
|
"\n", |
|
"rotation = [ 0.8126942 , 0.35465172, -0.43531808, 0.15571932]\n", |
|
"scene = draw.Scene(\n", |
|
" prim, zoom=4, features=features, rotation=rotation)\n", |
|
"scene.show()" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [] |
|
} |
|
], |
|
"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.7.3" |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 2 |
|
} |