File:ConvexCombination-2D.gif
From testwiki
Jump to navigation
Jump to search
Size of this preview: 600 × 600 pixels. Other resolutions: 240 × 240 pixels | 480 × 480 pixels | 1,000 × 1,000 pixels.
Original file (1,000 × 1,000 pixels, file size: 331 KB, MIME type: image/gif, looped, 92 frames, 0.9 s)
Note: Due to technical limitations, thumbnails of high resolution GIF images such as this one will not be animated.
This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.
Summary
| DescriptionConvexCombination-2D.gif |
Convex combination of three points |
| Date | |
| Source | Own work |
| Author | Damodar Rajbhandari |
Source code in Python 3.x (in Jupyter Notebook)
# Damodar Rajbhandari (2022)
import matplotlib
matplotlib.rcParams['text.usetex'] = True # uncomment if you donot have latex installed
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import rc
from IPython.display import Image
rc('animation', html='html5')
plt.rcParams.update({'font.size': 13})
# animate point P = alpha0 * v0 + alpha1 * v1 + alpha2 * v2
fig = plt.figure(figsize=(10, 10))
fig.tight_layout()
pls = []
x = [2, 4, 12]
y = [1,7, 6]
plt.plot(x, y, 'o', color='black')
# plot dots with labels v0, v1, v2
for i in range(3):
plt.text(x[i]-.37, y[i]+.1, '$v_'+str(i)+'$')
plt.text(1.5, 8, '$P := \\alpha^0 v_0 + \\alpha^1 v_1 + \\alpha^2 v_2$')
plt.fill(x, y, color='green', alpha=0.3)
plt.xlim(0, 15)
plt.ylim(0, 9)
for alpha1 in np.arange(-0.1, 1.2, 0.1):
for alpha2 in np.arange(-0.2, 1, 0.1):
alpha3 = 1 - alpha1 - alpha2
if alpha3 >= 0:
x = alpha1 * 2 + alpha2 * 4 + alpha3 * 12
y = alpha1 * 1 + alpha2 * 7 + alpha3 * 6
pl, = plt.plot(x, y, 'o', color='red')
npl = plt.text(x-.35, y+.1, 'P')
a1 = plt.text(1.5, 8.5, '$\\alpha^0$ = '+str(round(alpha1, 2)))
a2 = plt.text(4.5, 8.5, '$\\alpha^1$ = '+str(round(alpha2, 2)))
a3 = plt.text(7.5, 8.5, '$\\alpha^2$ = '+str(round(alpha3, 2)))
a1a2a3 = plt.text(10.5, 8.5, '$\\alpha^0 + \\alpha^1 + \\alpha^2$ = '+str(round(alpha1+alpha2+alpha3, 2)))
myp = plt.text(5.3, 8, '$ = '+str(round(alpha1, 2))+r'\left(\begin{array}{c} 2 \\ 1 \end{array}\right) + '+str(round(alpha2, 2))+r'\left(\begin{array}{c} 4 \\ 7 \end{array}\right) + '+str(round(alpha3, 2))+r'\left(\begin{array}{c} 12 \\ 6 \end{array}\right) = '+r'\left(\begin{array}{c}'+str(round(x, 2))+r'\\'+str(round(y, 2))+r'\end{array}\right)$')
pls.append([pl, npl, a1, a2, a3, a1a2a3, myp])
# make a trace dashes line of previous points
for i in range(len(pls)-1):
plt.plot([pls[i][0].get_xdata()[0], pls[i+1][0].get_xdata()[0]], [pls[i][0].get_ydata()[0], pls[i+1][0].get_ydata()[0]], '--', color='red')
# create the animation
ani = animation.ArtistAnimation(fig, pls, interval=50, blit=True)
ani.save('convex-combination.gif', writer='imagemagick', fps=70)
with open('convex-combination.gif','rb') as f:
display(Image(data=f.read(), format='png'))
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
This media file is uncategorized.
Please help improve this media file by adding it to one or more categories, so it may be associated with related media files (how?), and so that it can be more easily found.
Please notify the uploader with {{subst:Please link images|File:ConvexCombination-2D.gif}} ~~~~ |
Captions
Convex combination of 2-simplex
Items portrayed in this file
depicts
some value
11 December 2022
image/gif
f26eeeabd5187e3c32e646d0c1421e495bc9aa0f
339,251 byte
0.9200000000000006 second
1,000 pixel
1,000 pixel
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 03:01, 11 December 2022 | 1,000 × 1,000 (331 KB) | wikimediacommons>Drhere | better quality animation using python and LaTeX |
File usage
The following page uses this file: