{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting Bézier triangular patches with Python Plotly ##" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The de Casteljau algorithm for computing points on a triangular Bézier patch ###" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A Bézier triangular patch is a parameterized polynomial surface. Its parameters belong to a triangular 2D region, $T$.\n", "The triangle vertices, $T_0, T_1, T_2$, are denoted counterclockwise like in the figure below:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAARsAAAEbCAYAAADqLSAhAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4xMJremEEA\nAAy4SURBVHic7d29bhznFcbx5wQxHCTVuklKg7oEpghcpSCbNEEKCsgN0JcgXQJ5BYF4AwHMIkiK\nNGKRKoAB7w0EEJOUbsQUiRFDRk6KGYqr9X68sztz3o/5/wDB4nIljgHi0Xmf2bM0dxcATO2HuS9g\nCDM7lbToP3xw96WZLSSd9o8t3f0hz9UB2OUHuS/gAJeSXuspdB4fW2x+OoASVBU27r6U9LL/8Gzl\nU/fufstUA5SrqrCRJHe/l3Qr6bI/Qr2QdJf3qgDsU13Y9G7UHZsuJC3cnbABCme13o0ys9fqjlLn\nhA1QvlonG6mbbu4JGqAOVYWNmS3M7GTloetsFwNgkKpeZyPplbqu5lzSmbt/nvl6ACSqqrPpX9R3\n0X9409+ZAlCBqsIGQL2q6myGMOMVxUBJmgwbM51KekvgAOVoMmz01Ouc7XwWgDCths1v+v9+lvUq\nALzXXEHcH53e9h9+7a6f5bweAJ0WJ5szSd/1v/+pmU52PRlAjBbD5jM9vVjxW9HbAEVoMWx+u/L7\njyX9OteFAHjSVGfTH5nerD38jbt+kuN6ADxpbbI5U3d0WvXj/nU3ADJqLWx+qe7otOqd6G2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L+lTSt5I+VveD\nEG/VBc/d5F+fsAHmYSVs1r2T9JGkLyX9QV34LEf/+oQNMA87wmbVY/B8I+kvkv6oLnzuj/76hA0w\nD4lhs+7xyPW1pN9L+qsO7HtM8jeSTob+QQCz9mzotMNkA8zEgZONJH2n7s7139R1OreHdDrc+gaw\nbrSj0yrCBsBjKfwfSX9SVwwnl8Jmdipp0X/44O7L1cfc/U4ibIC5egyYu8dfR97uPpP0QtJLScv+\n4xN1r+ORRNgAc/JPSf/TyC/kc/elpKWZLSS9MLN7SQt3/3z1eRTEAEZjZl9JOpX0zN0/OIaxiAlg\nFP1ks1S3BnG1/nnCBsBYvpB0I+m5pDMz+yBwOEYBOEofKmfqeppn/WNv1d2NupP00t2XhA2AEByj\nAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwA\nhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACE\nIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIQgbACEIGwAhCBsAIRo\nOWzuc18AgCf/B7Q5o3KCwFvEAAAAAElFTkSuQmCC\n", "text/plain": [ "" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import Image\n", "Image(filename='Imag/triangle.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Each point $P$ in $T$ is expressed as a convex combination of the vertices $T_0, T_1, T_2$:\n", "\n", "$P=\\lambda_0T_0+\\lambda_1T_1+\\lambda_2T_2$, $\\lambda_i\\geq 0$, $i=\\overline{0,2}$, and $\\lambda_0+\\lambda_1+\\lambda_2=1$\n", "\n", "The scalars $\\lambda_i$ are the *barycentric coordinates* of the point $P$.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "If $(x_i, y_i)$ are the cartesian coordinates of the vertices $T_i$, $i=\\overline{0,2}$, and $P(x, y)$ \n", "is a point in the corresponding triangular region, then its baycentric coordinates are given by \n", "the solution of the linear system:\n", "\n", "$$\\left[\\begin{array}{ccc} \n", "x_0&x_1&x_2\\\\\n", "y_0&y_1&y_2\\\\\n", "1&1&1\\end{array}\\right]\n", "\\left[\\begin{array}{c}\\lambda_0\\\\\\lambda_1\\\\\\lambda_2\\end{array}\\right]=\n", "\\left[\\begin{array}{c} x\\\\y\\\\1\\end{array}\\right]$$\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is a one-to-one correspondence between the points of the triangle $T$ and the triangle $\\Delta$, in 3D, of vertices\n", "$A_0(1,0,0)$, $A_1(0,1,0)$, $A_2(0,0,1)$. Namely, to each $P(x,y)\\in T$ one associates its barycentric coordinates $(\\lambda_0, \\lambda_1, \\lambda_2)\\in\\Delta$.\n" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAARQAAADoCAYAAAAuVxuvAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4xMJremEEA\nABO8SURBVHic7d1LbB3XfQbwb3jvpSiRlBU9rFfgpHIcN/BGdYzUdRHPmcBtUARdtCkKJKsC3rSb\noosWRVEXcwZBF0G966Yo0K66K1AkAdoUSOM5YyEF0kJOgaRB6ipKrIflWIaSVJJF0iSni+G5HF5e\ncu5jZs5jvh9AiJeiqLl8fDzn/z9zTpDneQ4iohr0TV8A1UcpBaXUvrcLISCEaP16qHsWTF8A1Ucp\nhSRJ9ryuHxO1gYHimTiOIaUcPg7DkKMTag2nPB7RwSGEQJZlCMNw7BSIqCkBi7J+UUohiiIAQJqm\nw0Apj1qImsIpj2fKYSKE4AiFWsVA8Ui5VqKUGk59iNrCKY9HDprWsG1MbWGgEFFtOOUhotowUByn\n1BXTl0A0xCmP44Lg95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AibuE4icsBMgXLq1N9ie3sD\nly//cCdIfrWJayMix0wdKEq9iSz7L8Tx7zZ1TUTkKONbQBKRP/4f3ZZ0YY5FHTEAAAAASUVORK5C\nYII=\n", "text/plain": [ "" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Image(filename='Imag/triangle3D.png')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "A Bézier triangular patch is defined by an integer $n>0$, and a triangular net of 3D points\n", "${\\bf b}_{ijk}$, with $i, j, k\\geq 0$ integers such that $i+j+k=n$. Its parameterization is:\n", "$S: (\\lambda_0, \\lambda_1, \\lambda_2)\\in \\Delta \\to \\sum_{i+j+k=n}\\frac{n!}{i!j!k!}\\lambda_0^i\\lambda_1^j\\lambda_2^k {\\bf b}_{ijk}$ " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since the sum of powers of $\\lambda_0, \\lambda_1, \\lambda_2$ is $n$, the patch is said to have the total degree $n$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A point on such a surface corresponding to the parameters $(\\lambda_0, \\lambda_1, \\lambda_2)$ is computed recursively by the *triangular de Casteljau algorithm*:" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "$$\\begin{array}{lll}\n", "{\\bf b}_{ijk}^0&=&{\\bf b}_{ijk}\\\\\n", " {\\bf b}_{ijk}^r&=&\\lambda_0{\\bf b}_{i+1\\,j\\,k}^{r-1}+\\lambda_1{\\bf b}_{i\\, j+1\\, k}^{r-1}\n", "+\\lambda_2{\\bf b}_{i\\,j\\,k+1}^{r-1},\\end{array}$$ \n", "where $r=\\overline{1,n}$, and $i+j+k=n-r$.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The last computed point, ${\\bf }b_{000}^n$, is a point on the surface." ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Details on the triangular Bézier patches can be found in:\n", " \n", " 1. G Farin, Curves and Surfaces for Computer Aided Geometric Design: A Practical Guide, Morgan Kaufmann, 2002.\n", " 2. J. Gallier, Curves and Surfaces in Geometric Modeling: Theory and Algorithms, Morgan Kaufmann, 1999. \n", " A free electronic version can be downloaded [here](http://www.cis.upenn.edu/~jean/gbooks/geom1.html). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " The $(n+1)(n+2)/2$ control points, ${\\bf b}_{ ijk}$, are placed in a triangular structure in the same way as\n", " the points $(i/n, j/n, k/n)$ are located in the triangle $\\Delta$ of vertices $A_0(1,0,0)$, $A_1(0,1,0)$, $A_2(0,0,1)$. \n", " \n", "We illustrate here the case $n=3$:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAakAAAEQCAYAAAAK6YvmAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4xMJremEEA\nAB9cSURBVHic7d29biPNd+fxX9kPsInttZw4XIBzAwb4BL4AziVQm2221A0sQBpOHDigLkFKHBkL\naDKHKyabD7GLzUfYjb14iD9sA3ZgHwd9WtNqdZPV72/fD0CMRlKRLXazqqvq1KlgZgIAYIx+GfoA\ngKULIawk7SRdJD2b2aVCuY2kuyrlmpYF+vR7Qx8AsGTeWHyX9KikwXitUO5F0jdJZ/+6ymvWKgv0\njUYK6FEI4S6EsM186yLpOff/GFtJFzO7mNlJ0iaEsG5atuD4gEHRSAEVhBCOIYSnBk+xN7Nv6X+8\noThI2itpPA6Rz3MX+b1KZX3Y7xJC2EQ+F9ApGimgmq2kXQghtkF4F0LY6WOvKf3+yhuqR0mvdZ67\nTd67ojeFUaCRAiL5MFg6HLev8RQbM3vLPedeyZyUJL0p6dGsIp7rreB758jjiCl78kYVGBSNFBBv\nI+nBv67U0/A5n6LG4aSkQdgqafgezexmY2Nmz/682xDC0ctFzWfFlPUhSYb8MLjAOingNo+I25vZ\n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vtVG2brlPjZS3yCd9/gP3SnpYB/+9NL1F2sO62Uj1/cc1LTtXnIfp4FzB\n7cysaI+9dDlNtpe90sce9EUFPfVwJUWRz5FeygJ56pa9Vi53vO+K5qQ2Ssa9T+lDet+A8L1ndWMd\nRuGbkh5kKFnJHkJYly1Oq1vuVtncMc8N52E6OFf4xOeYnuQjWZnvr5XUx3fZnq8HmT3mGoiTvDHL\n/N6tBAl7SYXzmHXLRpTLhte/+73MD3chhHR1en5V+4sXXIUQvkdMwn56Uzr+45q8oYVvzExwHqaD\nc4VPvKPwYGa/Zhsej5R7MLOQ9nx9eubk81Lr7O/q8w3Q1QQJvk6ubHi3btmYpAyfYh/eh/t8vLnw\noCwy8WDm98+heA3FzT8uFK9kr1vuZllXJShkMjgP08G5QhPeQB0lvflcVX5o8BRC2KSxAz7MdvAO\nx1Y/A9OyCnvQdctGllt9mvs0s0YPJXdZx4Lvb5UsTiwqc1Syh9S6qNyV16pVLqLsp+Ofy4PzMJ0H\n54pHlw8lvee7zP9X/u9O0m+5n22y/y94rlplb5TbFV5rDf/o9CIua6j2+YPt6I9r8oYWvjFzenAe\npvPgXPHo8pGeN7/OfstcCxZ7TuuWvVZOSc+r8Dl6e1O6+uO6emPm9uA8TOfBueLR9UPJ/OeLkt57\nYSej7bJ1y/W66aFP5u2VjGWni89uhrvWLde07FxxHqaDc4WlY2deAMBo9b4zLwAAsf4d8Y4ko8dl\nl3EAAAAASUVORK5CYII=\n", "text/plain": [ "" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Image(filename='Imag/ijk.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hence to generate a Bézier triangular patch of total degree $3$ we start with a net of points:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$\\begin{array}{lllllll}\n", " & & & {\\bf b}_{300} & & & \\\\\n", " & & & & & & \\\\\n", " & & {\\bf b}_{210} & & {\\bf b}_{201} & & \\\\\n", " & & & & & & \\\\\n", " & {\\bf b}_{120} & & {\\bf b}_{111} & & {\\bf b}_{102} & \\\\\n", " & & & & & & \\\\\n", " {\\bf b}_{030} & & {\\bf b}_{021}& & {\\bf b}_{012} & & {\\bf b}_{003}\n", "\\end{array}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The point indices in a triangular net or the indices that define points in a triangular grid of $\\Delta$, as above,\n", " are returned by the following function::" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def indexes(n):\n", " return [(i,j, n-(i+j)) for i in range(n,-1, -1) for j in range(n-i, -1, -1)]" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[(3, 0, 0), (2, 1, 0), (2, 0, 1), (1, 2, 0), (1, 1, 1), (1, 0, 2), (0, 3, 0), (0, 2, 1), (0, 1, 2), (0, 0, 3)]\n" ] } ], "source": [ "print indexes(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In each step, $r$, of the de Casteljau recursive formula, one computes succesively the convex combinations with the same coefficients, $\\lambda_0, \\lambda_1, \\lambda_2$, of all triplets of nearby points\n", "in the net ${\\bf b}^{r-1}_{ijk}$. The relative position of points in a such triplet is illustrated in the next cell:\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$\\begin{array}{lll} & *& \\\\\n", "*& &*\\end{array}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following we give the nets of points resulted from each step $r$.\n", "Starting with the initial control points:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$\n", "\\begin{array}{lllllll}\n", " & & & {\\bf b}^0_{300} & & & \\\\\n", " & & & & & & \\\\\n", " & & {\\bf b}^0_{210} & & {\\bf b}^0_{201} & & \\\\\n", " & & & & & & \\\\\n", " & {\\bf b}^0_{120} & & {\\bf b}^0_{111} & & {\\bf b}^0_{102} & \\\\\n", " & & & & & & \\\\\n", " {\\bf b}^0_{030} & & {\\bf b}^0_{021}& & {\\bf b}^0_{012} & & {\\bf b}^0_{003}\n", "\\end{array}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "the step $r=1$ computes the points:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$\n", "\\begin{array}{lllll}\n", " & & {\\bf b}^1_{300} & & \\\\\n", " & & & & \\\\\n", " & {\\bf b}^1_{210} & & {\\bf b}^1_{201} & \\\\\n", " & & & & \\\\\n", " {\\bf b}^1_{120} & & {\\bf b}^1_{111} & & {\\bf b}^1_{102} & \n", " \\end{array}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "while $r=2$, the points:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$\\begin{array}{lll}\n", " & {\\bf b}^2_{300} & \\\\\n", " & & \\\\\n", " {\\bf b}^2_{210} & & {\\bf b}^2_{201} \n", " \\end{array}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the last step, $r=3$, we get the point on the surface, ${\\bf b}^3_{300}$, corresponding to the parameters $(\\lambda_0, \\lambda_1,\\lambda_2)$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To implement the de Casteljau algorithm we store the control points in a list of points, concatenating the rows of the theoretical triangular net." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We define the function deCasteljau_step that evaluates the convex combinations for one step of the de Casteljau formula. Its arguments are\n", "the degree n, the list of points, b, and the triplet of barycentric coordinates, lam:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "from __future__ import division" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def deCasteljau_step(n, b, lam):\n", " \n", " i=0\n", " j=1\n", " for nr in range(1, n+1):\n", " for k in range(nr):\n", " b[i]=lam[0]*b[i]+lam[1]*b[j]+lam[2]*b[j+1]\n", " i+=1\n", " j+=1\n", " j+=1\n", " return b[:-(n+1)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "de Casteljau algorithm is implemented by the following recursive function:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def deCasteljau(n,b,lam):\n", " \n", " if len(b)>1: \n", " return deCasteljau(n-1, deCasteljau_step(n, b, lam), lam) \n", " else: \n", " return b[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### A discretization method of a triangular Bézier patch for plotting with Plotly ###" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " In the following we present a method of discretization of a triangular Bézier patch, such that to get the data that define a plotly Surface.\n", " \n", " The basic idea is to define a rectangular grid that covers the triangle $\\Delta$ of barycentric coordinates. The deCasteljau function, evaluated at each point $(\\lambda_0, \\lambda_1, \\lambda_2)$ of this grid, defines a triangular net of points on the surface. These points are then integrated into a meshgrid over the rectangle \n", " [min(X), max(X)], [min(Y), max(Y)], where X and Y are the lists of x, respectively y-coordinates of the points on the surface.\n", " \n", "\n", "We start with a triangular grid of the triangle $\\Delta$ constructed from indexes returned by the function indexes, called for an even integer $2m$. \n", " \n", " We illustrate our method for a low value of $m=4$ (see the next image). \n", " " ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVQAAAD9CAYAAADj9o8nAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4xMJremEEA\nABgoSURBVHic7d1vbG1pVcfx38LRYWb4d4YIg5IQzySCEXDMmYiZGP9xroF5AWI8zQzyx2A85w0R\nXkDaaNTRF6Y1JMZETFqiUSEOthCU6GBslRBDRqENY5xIwLSSIJGBcIvz5w4kg8sXz3N6d3dPb3va\nffbz7L2/n+SEuefeO6x52rO69vOsvba5uwAAl/es1AEAQFuQUNE4ZrZqZuup4wDKjEt+NI2Z7Uvq\nS7rd3Q9TxwNMUaGiUcxsJGmaRJdTx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uzeQx\nsWaXiS3Pz0BH88bZFar7nsyWFMriQ0kblWXzy1uRdKBQRW/FVy6uKFzC9iRtyT2LS0SFr9+hwtdz\nT3l9PVmz+eX5GWhR3jCzvruf67bVhT71FACazsziHaFnJ9Ubtk2Z2aqZrVcWGQA0iJmNFSrZc7V+\nndWHOpI0thx77wBggWLeO9QcHQCnJlQzm+59SEr7aFYASGDk7tP91XN1AtyoQh1KR7dnjS4TFQA0\niYW7qKaHoueeozozoVq8VczDKeuWpH6sWAGgC/p+vcvkxKxnMxvG17G8eFqFOtb1NodpyTszoZpZ\n33K9jxgA5hQPog6nSVOhjW9Q/n1335E0LOa/0/pQh/EvFpPoqNiPFavYsUKi3VJFt24BQCrTg6jC\n3qnMTDp+jnSocOq/F/95qJj/TiTUmH13dDJBLisk0BVJiol1xXKdDAQA8xu7+9qM94/yXDHZKiTW\no7nQsy75h5LW3H1n+lIYzCpxOAWgheLl/brilXjh/YFC3uuZ2Wrp7ywr5MqjQ6ujO6ViZTqdLLXn\n7lcKf3E7vt9TKHN33H2l8Ht7018DQNvF7dADd98zs8H0AOvokt/dN3TK/bbF5AoAXRaT6aqkg7i/\nerRFcMnHSNuqQlV7IKpUAB3HcBQAqMhFn3oKACj5f7RrLTNVyIRyAAAAAElFTkSuQmCC\n", "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Image(filename='Imag/triangulation.png')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "On each side we have $2m+1$ points. Considering the points on the side $A_1A_2$ as reference points, we exclude from this grid the points that\n", "do not lie on perpendiculars at reference points, on $A_1A_2$. That is, we remove the points in the odd rows (parallel to $A_1A_2$).\n", "\n", "In fact we define a function even_rows that just generate only the points in the even rows of the above triangulation:\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def even_row_pts(p):#p=2*m\n", " \n", " if p%2:\n", " raise ValueError('p must be an even integer')\n", " I=[2*k for k in range (p+1)]\n", " return [(i/p,j/p, 1-(i+j)/p) for i in I[::-1] for j in range(p-i, -1, -1)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and get a less dense grid:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVQAAAD9CAYAAADj9o8nAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4xMJremEEA\nABRCSURBVHic7d1fiGTpWcfx3yOrq7OJplzUjQaECriKu3GlFoRFEEkNZPdivapmIyERxKobMblQ\nuhGExatqELyKUB280AQ2dOdGwY3QLSISVmQaIy6GKNMKIZhVMh13sxMFw+vF+1bP6erq7vpzznn/\nnO8Hip2pmdl99vTU08953+d9jjnnBADY3vfEDgAASkFCRXbMbGpms9hxAIuMW37kxszuS+pL+mHn\n3HnseIA5KlRkxcxGkuZJdDdmLMAiEipyM5Q0CT8exQwEWERCRTbMrC9JzrlTSUeS+qFiBZJAQkVO\nxpIOwo+Pwj+vJFQz65vZ2Mx2zazXWnTovMdiBwCsYShdrKPOjcys75w7C7/Wl3Qo6a6kQeXHQOOo\nUJEFMxtLOll47YdfHld+60jSuXPu3Dl3ImloZoNWg0VnUaEiF0NJk2qblJmdyu/0jyTthbeX3eJz\n249WUKEiaWEt9Fg+oR4u/PKhfAtV38zumdm09QCBChr7UZSwNDByzt0NP3fiAABaQkJFcUJFeyC/\nKSXn3N7NfwKoBwkVafEVZk/SgagqkRkSKtLx6Iz+3AcV2qGAHLAphTSYDXU5mUqX26GA5JFQAaAm\nJFSkwbmTt/TUt6tvva6XPx8rHGATrKEiCWYaS5p+Sb/4Ry/oS+88pbc+8pZ+9L+c007s2IBVkVAR\nnZn6ku5J2nfOHydd9h6QOhIqojPTsaTzxWrUTCNJM0l3ndNplOCANZBQEZWZpvK7+R90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U9/6qf01XnF0HuoO598wuLfbXDNNpPqZ+CLevGlj+iL1TuN8Sfsc3+bRt74s+fu6OH8\n7rwvn+NqOfO/SkK9cvv1AX3tdyV9vY4ANvWM3vyBO3r4/up779U7vyzp8UghXfiAvvYTi++9qydG\nkp6NEM4l79U7L1R/fkcP3/+M3nz1TT3znVgxSVyzTaT8GXhXT/z04nup5g35J6fWY4XSfVAp252T\nHsQu2SuxHS7EltKt2IOF2AbRY/Jx7S7EdRg9Jq7ZNrGl+RnoaN64vUJ17lRmO/Jl8bmkg9qy+fb2\nJJ3JV9FH4ZWKu/K3sD1JR3IuiVtE+a/fufzX81RpfT25ZutL8zNQUN4ws75zbqVjq40+9RQAcmdm\n4UTo7Un1xrYpM5ua2ay2yAAgI2Y2lq9kV2r9uq0PdSRpbCn23gFAg0LeO9caHQDXJlQzm699SIr7\naFYAiGDknJuvr67UCXBThTqULo5njbaJCgByYv4U1XxTdOU5qksTqoWjYs7vsh5J6oeKFQC6oO8e\ndZlcmfVsZsPwupQXr6tQx3rU5jAveZcmVDPrW6rniAFgTWEj6nyeNOXb+AaLv+6cO5E0rOa/6/pQ\nh+EPVpPoqNqPFarYsXyiPVJNR7cAIJb5RlRl7VRmJl3eRzqX3/U/DT8eKuS/Kwk1ZN8TXU2Qu/IJ\ndE+SQmLds1QnAwHA+sbOuf0l71/kuWqylU+sF3Ohl93yDyXtO+dO5i/5wawSm1MAChRu72cKd+KV\n9wfyea9nZtOFP7MrnysvNq0uTkqFynQ+WerUOXe38gePw/s9+TL3xDm3V/m10/nPAaB0YTn0zDl3\namaD+QbWxS2/c+5A15y3rSZXAOiykEynks7C+urFEsGWj5G2qXxVeyaqVAAdx3AUAKjJpk89BQAs\n+H+bwZjKRFc2rQAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Image(filename='Imag/even_rows.png')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ " Now to each two consecutive points placed on the same perpendicular to $A_1A_2$ one associates the mid point. Thus we construct \n", "additional points to the initial grid (the green points in the next image):" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def additional_weights(m, weights):\n", " \n", " wei=map(np.array, weights)\n", " new_weights=[]\n", " a=0\n", " for k in range(1, m+1):\n", " for j in range(1,2*k):\n", " new_weights.append((wei[a]+wei[a+2*k])/2)\n", " a=a+1\n", " return list(map(tuple, new_weights)) " ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "The function grid mixes the two lists of points:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def grid(m, weights, new_weights):\n", " \n", " L=len(weights)\n", " barycenters=[]\n", " for k in range(m):\n", " L=2*k+1\n", " enD=k**2+L \n", " barycenters +=weights[k**2: enD] +new_weights[k**2: enD]\n", " barycenters+=weights[m**2:] \n", " return barycenters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and the final grid of the triangle $A_0A_1A_2$ looks as follows:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVQAAAD9CAYAAADj9o8nAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAHXRFWHRTb2Z0d2FyZQBHUEwgR2hvc3RzY3JpcHQgOS4xMJremEEA\nABeYSURBVHic7d1fiKzJWcfx3yNHV3cTTWdRNxoQOmAUd+PKuyAsDiLpgSQX61UPiYREELtvxORC\nmUEQGq9mQPAqQk/wQhPYMJMbBTfCjIgMYUWmMeJiiHJGIQSzSs7E3exGwVBeVPWcd3p6Zrr7/VP1\nvu/3A82e0+fMbJ23p59+quqp5zXnnAAAxX1f7AEAQFsQUNE4ZrZvZtPY4wAWGVN+NI2ZPZTUl/Ru\n59xl7PEAc2SoaBQzG0qaB9HdmGMBFhFQ0TQDSePw62HMgQC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LgrQx1IV8ezhkVGBQBNYv4U1XxTdOU+qksDqoWjYs7vsh5L6oeMFQC6oO8e\nV5nc6PVsZoPwuBYXb8tQR3pc5jBPeZcGVDPrW6rniAFgTWEj6nIeNOXL+LLFP3fOnUoa5OPfbXWo\ng/CF+SA6zNdjhSx2JB9oj1XS0S0AiGW+EZVbO5WZSdf3kS7ld/1n4dcDhfh3I6CG6HuqmwFyVz6A\n7klSCKx7lmpnIABY38g5d7Dk+as4lw+28oH1qi/0sin/QNKBc+50/pBvzCqxOQWghcL0fqowE889\nn8nHvZ6Z7S98za58rLzatLo6KRUy03lnqZlzbjv3hSfh+Z58mnvqnNvL/dls/nsAaLuwHHrhnJuZ\nWTbfwLqa8jvnDnXLedt8cAWALgvBdF/SRVhfvVoiKHgbaduXz2ovRJYKoONojgIAJdn0rqcAgAX/\nD2pIzxm63VRjAAAAAElFTkSuQmCC\n", "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Image(filename='Imag/finalgrid.png')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "To each point (triplet of weights) in this grid one associates a point on the Bézier patch. \n", "\n", "The following function discretizes a Bézier surface of degree n, control points b, and grid points barycenters, defined above:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def surface_points(n, b, barycenters):\n", " \n", " points=[]\n", " for weight in barycenters:\n", " b_aux=np.array(b)\n", " points.append(deCasteljau(n, b_aux, weight))\n", " return zip(*points) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to plot the discretized patch we need to construct three arays of shape (2m+1,2m+1) (or a list of lists) that contain in an appropriate position\n", "the x, y, respectively z-coordinates of the computed points.\n", "\n", "The values in a list of coordinates are placed succesively in the red positions, while outside the triangle, similar to the triangle $A_1A_1A_2$, we store None values:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSU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7FA9Reoai5vGrPgjhBAF8CpUl1hB6t6X/v+aN0/5fao/oHB1FiGEiMp7Dxh9k0MtUT9QCCH2\njffWd/6iQ218oVKkhBBHx3sGlG9xqO8a8gohxKHx1pDnq4tSXiygj3ZDCSGOm3p2/moBlbUj1Ebx\n1XMVjBZCHDtv8YmvOdR7YJazRqdCCAFf3ti00qGqYLQQQqzmta33L2KoKhgthBCvsrYgtTnUlCak\nlEkp/3O+9U+/yQ//erjdUClVpHRb6ySlD5fY2iop9UnpwTU++jno8Uhp6Pqy6+13LWklDdv05191\nLekFss2yBLdNL0A9+qv86lcvbDPDJENuXbc5Z0JdcLtC56RzXcsaqwyPK3QOOte2rHOwQuNjhqpz\nbcs6ZZvlNMo2y+pcaZtfg5Wb/wd/Mv3gb/17/sRPduz8V/KL/ODr/85ywJb4Md8Y/XzqQtFqfo3v\n/pG/xK+9GEF9n29/b5D4Z11oWsUd3/5T3+b77dvVX+O7f/+7if/UhaZV/E++MfoGP27flm1+ANlm\nWdbZ5saH9AkhhHA0rSqqUdOqsjplm+U0HQBV7QAAADxJREFUyjbL6lxpm6t+eRtO/LNB3IY12Ged\n/QwPDUMYdq5ptc5ho4M9ZOh3rmm1TtlmOZ2yzbI6X9jm/wfdDc162P0qTwAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Image(filename='Imag/gridData.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The function move_data_to_triangle returns a list of lists. The values in a list of coordinates, D, are assigned correspondingly to locations placed within the formal triangle included in this list of lists:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def move_data_to_triangle(m, D):\n", " \n", " DD=[]\n", " pos=0\n", " for i in range(m):\n", " L1=[None]*(2*m+1)\n", " L2=[None]*(2*m+1)\n", " idx=[m-i+J for J in range(2*i+1)] \n", " \n", " for k in range(2*i+1):\n", " L1[idx[k]]=D[pos]\n", " pos+=1 \n", " for k in range(2*i+1):\n", " L2[idx[k]]=D[pos]\n", " pos+=1\n", " \n", " DD.append(L1)\n", " DD.append(L2)\n", " K=-(2*m+1) \n", " DD.append(D[K:]) \n", " return DD\n", " " ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ " set_data_for_Surface includes all previous functions that prepare data for a plot:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def set_data_for_Surface(n, b, m):\n", " \n", " if len(b)!=(n+1)*(n+2)/2:\n", " raise ValueError('incorect number of control points')\n", " weights=even_row_pts(2*m)\n", " new_weights=additional_weights(m, weights)\n", " grid_pts=grid(m, weights, new_weights)\n", " X, Y, Z=surface_points(n, b, grid_pts)\n", " ZZ=move_data_to_triangle(m, Z)\n", " XX= move_data_to_triangle(m, X)\n", " YY=move_data_to_triangle(m, Y)\n", " return [XX, YY, ZZ]" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "A colorscale derived from the future viridis [colormap](http://matplotlib.org/style_changes.html) is used to plot a Surface:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": true }, "outputs": [], "source": [ "viridisCS=[[0.0, '#440154'],\n", " [0.06274509803921569, '#48186a'],\n", " [0.12549019607843137, '#472d7b'],\n", " [0.18823529411764706, '#424086'],\n", " [0.25098039215686274, '#3b528b'],\n", " [0.3137254901960784, '#33638d'],\n", " [0.3764705882352941, '#2c728e'],\n", " [0.4392156862745098, '#26828e'],\n", " [0.5019607843137255, '#21918c'],\n", " [0.5647058823529412, '#1fa088'],\n", " [0.6274509803921569, '#28ae80'],\n", " [0.6901960784313725, '#3fbc73'],\n", " [0.7529411764705882, '#5ec962'],\n", " [0.8156862745098039, '#84d44b'],\n", " [0.8784313725490196, '#addc30'],\n", " [0.9411764705882353, '#d8e219'],\n", " [1.0, '#fde725']]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import plotly.plotly as py\n", "import plotly.tools as tls\n", "from plotly.graph_objs import *" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [], "source": [ "py.sign_in('empet', 'my_api_key')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "plot_Surface generates a triangular Bézier patch of degree n and control points b, over the triangular grid of $2m+1$ points on each side of the barycenter triangle $\\Delta$:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def plot_Surface(n, b, m, plot_title): \n", "\n", " x, y, z= set_data_for_Surface(n, b, m)\n", " \n", " trace = Surface(\n", " z=z, \n", " x=x, \n", " y=y, \n", " colorscale=viridisCS\n", " )\n", " \n", " axis = dict(\n", " showbackground=True, \n", " backgroundcolor=\"rgb(230, 230,230)\",\n", " gridcolor=\"rgb(255, 255, 255)\", \n", " zerolinecolor=\"rgb(255, 255, 255)\", \n", " )\n", "\n", " layout = Layout(\n", " title=plot_title, \n", " width=600,\n", " height=600,\n", " scene=Scene( \n", " xaxis=XAxis(axis),\n", " yaxis=YAxis(axis), \n", " zaxis=ZAxis(axis) \n", " )\n", " )\n", " fig = Figure(data=[trace], layout=layout)\n", " return fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally we generate our first Bézier patch of degree $n=4$, over a grid corresponding to $m=80$:" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": true }, "outputs": [], "source": [ "n=4\n", "b=[[2.0, 3.0, 2.0],\n", " [1.5, 2.25, 3.0],\n", " [2.5, 2.25, 5.0],\n", " [1.0, 1.5, 4.0],\n", " [2.0, 1.5, 5.0],\n", " [3.0, 1.5, 3.0],\n", " [0.5, 0.75, 1.0],\n", " [1.5, 0.75, 3.0],\n", " [2.5, 0.75, 1.0],\n", " [3.5, 0.75, 4.0],\n", " [0.0, 0.0, 2.0],\n", " [1.0, 0.0, 5.0],\n", " [2.0, 0.0, 3.0],\n", " [3.0, 0.0, 1.0],\n", " [4.0, 0.0, 4.0]]\n", "m=80" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fig=plot_Surface(n, b, m, 'Bezier triangular patch of degree 4')\n", "py.iplot(fig, filename='Bezier-triangular-patch')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plotting the control polyhedron of a triangular Bézier patch ###" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A Bézier triangular patch of degree $n$ and control points ${\\bf b}_{ijk}$ interpolates the corners of the triangular net formed by these points, that is, it interpolates\n", "the points ${\\bf b}_{n00}, {\\bf b}_{0n0}, {\\bf b}_{00n}$, and it is included in the convex hull of all its control points.\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "To illustrate this property we define the control polyhedron of the patch, i.e. the plotly trace\n", "we get connecting with lines the points in a triplet of nearby points." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The function triangles returns the lists of all triplets of nearby points in the triangular net ${\\bf b}_{ijk}$, $i+j+k=n$:" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def triangles(n, b):\n", " \n", " triplets=[]\n", " i=0\n", " j=1\n", " for nr in range(1,n+1):\n", " for k in range(nr):\n", " triplets.append([b[i], b[j], b[j+1]])\n", " i+=1\n", " j+=1\n", " j+=1\n", " return triplets " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and the function triangle_lines prepares data for a Scater3d trace of the control polyhedron edges:" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def triangle_lines(triplets):\n", "\n", " line_pts=[]\n", " for tri in triplets:\n", " x, y, z=zip(*tri)\n", " x=list(x)+[x[0]]\n", " y=list(y)+[y[0]]\n", " z=list(z)+[z[0]]\n", " line_pts.append(Scatter3d(x=x, y=y, z=z,\n", " name='',\n", " mode='lines+markers', \n", " line=Line(color='#000762',\n", " width=4),\n", " marker=Marker(\n", " symbol='dot',\n", " size=5,\n", " color='#000762')\n", " ) \n", " )\n", " return line_pts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The function plot_surface_polyedron plots both a Bézier patch and its control polyedron:\n", " " ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def plot_surface_polyhedron(n, b, m, plot_title):\n", " \n", " x, y, z= set_data_for_Surface(n, b, m)\n", " \n", " trace = Surface(\n", " z=z, \n", " x=x, \n", " y=y, \n", " colorscale=viridisCS\n", " )\n", " \n", " triplets=triangles(n,b)\n", " lines_pts=triangle_lines(triplets)\n", " \n", " axis = dict(\n", " showbackground=True, \n", " backgroundcolor=\"rgb(230, 230,230)\",\n", " gridcolor=\"rgb(255, 255, 255)\", \n", " zerolinecolor=\"rgb(255, 255, 255)\", \n", " )\n", "\n", " layout = Layout(\n", " title=plot_title, \n", " width=600,\n", " height=600,\n", " showlegend=False,\n", " scene=Scene( \n", " xaxis=XAxis(axis),\n", " yaxis=YAxis(axis), \n", " zaxis=ZAxis(axis) \n", " )\n", " )\n", " fig = Figure(data=[trace]+lines_pts, layout=layout)\n", " return fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Data for a cubic (degree $n=3$) triangular Bézier patch and its control polyhedron:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [], "source": [ "n=3\n", "d=[[2.5, 2.5, 1.5],\n", " [1.3, 2, 3],\n", " [3, 2.5, 3],\n", " [1, 1, 2],\n", " [2.5, 1, 4],\n", " [4, 1, 1],\n", " [0, 1, 1],\n", " [2, 0, 2],\n", " [3, -0.5, 1.5],\n", " [5, 0, -0.5]]\n", "m=80" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fig=plot_surface_polyhedron(n,d, m, 'A cubic triangular Bezier patch and its control polyhedron')\n", "py.iplot(fig, filename='Bezier-cubic')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Triangular Bézier graphs and their contour plots###" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A degree $n$ triangular Bézier patch is the graph of a function defined on a planar triangular region of vertices\n", "$T_0, T_1, T_2$, if its control points have the coordinates\n", "${\\bf b}_{ijk}=(x_{ijk},y_{ijk}, z_{ijk})$, $i+j+k=n$, where $(x_{ijk},y_{ijk})$ are points in the triangular region $T$, of barycentric coordinates $(i/n, j/n, k/n)$, and $z_{ijk}$ are real values set by the user.\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Initial data for defining such a graph are:\n", " - the degree, $n$\n", " - the triangle $T$ given as a list of three numpy arrays of shape (2,)\n", " - a list, b_z, of $(n+1)(n+2)/2$ real values representing $z$-coordinates of the control points " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The function:" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cartesian_coords=lambda w, T: w[0]*T[0]+w[1]*T[1]+w[2]*T[2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "calculates the cartesian coordinates of a point having barycentic coordinates $(w_0, w_1, w_2)$, with respect to a triangle $T$.\n", "\n", "The control points of the graph are returned by the following function:" ] }, { "cell_type": "code", "execution_count": 64, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def control_points(n, T, b_z):\n", " ind=indexes(n)\n", " weights=[(i/n, j/n, k/n) for (i, j, k) in ind]\n", " b_xy=[cartesian_coords(w,T) for w in weights]\n", " b_xy=map(list, b_xy)\n", " len_bxy=len(b_xy)\n", " b=[b_xy[k]+[b_z[k]] for k in range(len_bxy)]\n", " return b" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us define a Bézier triangular graph of degree $n=4$, over the triangle $T$:" ] }, { "cell_type": "code", "execution_count": 65, "metadata": { "collapsed": true }, "outputs": [], "source": [ "n=4\n", "m=80\n", "nr_ctrl_pts=(n+1)*(n+2)/2\n", "T=[np.array([0, 1.5]), np.array([-1,0]), np.array([1, 0])]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$z$-coordinates of the control points are set arbitrary in the interval $[1,5]$:" ] }, { "cell_type": "code", "execution_count": 66, "metadata": { "collapsed": true }, "outputs": [], "source": [ "b_z=1+4*np.random.random(nr_ctrl_pts)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then the control points of our graph are:" ] }, { "cell_type": "code", "execution_count": 67, "metadata": { "collapsed": true }, "outputs": [], "source": [ "b=control_points(n, T, b_z)" ] }, { "cell_type": "code", "execution_count": 69, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fig=plot_Surface(n, b, m, 'Graph as a triangular Bezier patch')\n", "py.iplot(fig, filename='triangular-Bezier-graph4')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Contour plot of a triangular Bézier graph ###" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Having a method to generate a triangular Bézier graph, we can generate its contour plot with Plotly." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We set the data for a plotly Contour, namely a 2D array or a list of lists for z-values on the surface, and two 1D lists for x, respectively y-coordinates of the grid points in the triangle $T$." ] }, { "cell_type": "code", "execution_count": 70, "metadata": { "collapsed": true }, "outputs": [], "source": [ "n=4\n", "m=80" ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "collapsed": true }, "outputs": [], "source": [ "weights=even_row_pts(2*m)\n", "new_weights=additional_weights(m, weights)\n", "grid_pts=grid(m, weights, new_weights)\n", "X, Y, Z=surface_points(n, b, grid_pts)\n", "ZZ=move_data_to_triangle(m, Z)[::-1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get the x-list for Contour:" ] }, { "cell_type": "code", "execution_count": 73, "metadata": { "collapsed": false }, "outputs": [], "source": [ "K=-(2*m+1) \n", "XX= [cartesian_coords(w,T)[0] for w in grid_pts[K:]] \n", "x=sorted(list(set(XX)))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and the y-list:" ] }, { "cell_type": "code", "execution_count": 74, "metadata": { "collapsed": false }, "outputs": [], "source": [ "I=[k**2 for k in range(m)]\n", "Lam=[]\n", "for k in range(m):\n", " Lam.append(weights[I[k]+k])\n", " Lam.append(new_weights[I[k]+k])\n", "Lam.append(weights[-(m+1)] ) \n", "YY=[cartesian_coords(w,T)[1] for w in Lam]\n", "y=sorted(list(set(YY)))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the triangular contour:" ] }, { "cell_type": "code", "execution_count": 76, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "title=\"Contourplot of a triangular Bezier function\"\n", "data = Data([\n", " Contour(\n", " z=ZZ,\n", " x=x, \n", " y=y,\n", " autocontour=False,\n", " zauto=False, \n", " contours=Contours(\n", " showlines=False, \n", " start =min(Z), \n", " end=max(Z),\n", " size=0.1\n", " ), \n", " colorscale=viridisCS, \n", " ),\n", " ])\n", "layout = Layout(\n", " title= title, \n", " font= Font(family='Georgia, serif', color='#635F5D'),\n", " showlegend=False,\n", " autosize=False,\n", " width=500,\n", " height=500,\n", " xaxis=XAxis(\n", " range=[min(x), max(x)],\n", " showgrid=False,\n", " ),\n", " yaxis=YAxis(\n", " range=[min(y), max(y)],\n", " showgrid=False,\n", " ),\n", " margin=Margin(\n", " l=40,\n", " r=40,\n", " b=85,\n", " t=100,\n", " pad=0,\n", " autoexpand=True\n", " ),\n", " )\n", "fig = Figure(data=data, layout=layout)\n", "py.iplot(fig, filename='Contourplot-triangular-Bezier-graph4')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another pair graph-contour plot can be seen here:\n", " - graph: https://plot.ly/~empet/2266/graph-as-a-triangular-bezier-patch/ \n", " - contour plot: https://plot.ly/~empet/2268/contourplot-of-a-triangular-bezier-function/ " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.core.display import HTML\n", "def css_styling():\n", " styles = open(\"./custom.css\", \"r\").read()\n", " return HTML(styles)\n", "css_styling()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }