-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurve.html
More file actions
240 lines (200 loc) · 18.7 KB
/
curve.html
File metadata and controls
240 lines (200 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<title>curve — VPython 3.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="cylinder" href="cylinder.html" />
<link rel="prev" title="cone" href="cone.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="curve">
<h1>curve<a class="headerlink" href="#curve" title="Permalink to this heading">¶</a></h1>
<img alt="_images/curve.jpg" src="_images/curve.jpg" />
<p>The curve object consists of a list of points connected by straight lines. If points are close enough together curves can appear smooth. Points are supplied as a list of vectors; points can also be appended one at a time to the curve.</p>
<dl class="py function">
<dt class="sig sig-object py" id="id0">
<span class="sig-name descname"><span class="pre">curve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pos</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">[vec(-</span> <span class="pre">1,</span> <span class="pre">3,</span> <span class="pre">2),</span> <span class="pre">vec(2,</span> <span class="pre">0,</span> <span class="pre">-</span> <span class="pre">1)]</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">color</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">color.yellow</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#id0" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>pos</strong> (<em>list of vectors</em>) – List of positions of points in curve. Default is [] (no points).</p></li>
<li><p><strong>color</strong> (<em>vector</em>) – Default <em>color.white</em></p></li>
<li><p><strong>radius</strong> (<em>scalar</em>) – The radius of the curve. Default is 0, which gives a very thin curve.</p></li>
<li><p><strong>size</strong> (<em>vector</em>) – Changing size scales the entire curve. Default <1,1,1>.</p></li>
<li><p><strong>origin</strong> (<em>vector</em>) – Changing the origin moves the whole curve. Default <0,0,0></p></li>
<li><p><strong>axis</strong> (<em>vector</em>) – Default <1,0,0></p></li>
</ul>
</dd>
</dl>
</dd></dl>
<p>Curve objects cannot be compounded. A curve can be neither transparent nor textured.</p>
<p>Attributes used less often:</p>
<dl class="py function">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">curve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">canvas</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">mycanvas</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">emissive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>retain</strong> (<em>scalar</em>) – Number of points to retain if points are continually added to the curve.</p></li>
<li><p><strong>shininess</strong> (<em>scalar</em>) – Default 0.6; Range 0-1.</p></li>
<li><p><strong>emissive</strong> (<em>boolean</em>) – Default False. Object glows, losing all shading, if True.</p></li>
<li><p><strong>visible</strong> (<em>boolean</em>) – If False, object is not displayed. Default: True</p></li>
<li><p><strong>canvas</strong> (<em>object</em>) – Default is <code class="xref py py-attr docutils literal notranslate"><span class="pre">scene</span></code>.</p></li>
<li><p><strong>up</strong> (<em>vector</em>) – A vector perpendicular to the axis.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<p>Curves cannot use <em>make_trail</em>.</p>
<section id="appending-points-to-a-curve">
<h2>Appending points to a curve<a class="headerlink" href="#appending-points-to-a-curve" title="Permalink to this heading">¶</a></h2>
<p>A curve can be created by appending points one at a time. In this case it is possible (but not necessary) to specify a different color and radius for each point in the curve, as is done below:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">mycurve</span> <span class="o">=</span> <span class="n">curve</span><span class="p">()</span>
<span class="n">mycurve</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pos</span><span class="o">=</span><span class="n">vector</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="o">.</span><span class="n">red</span><span class="p">,</span>
<span class="n">radius</span><span class="o">=</span><span class="mf">0.05</span><span class="p">)</span>
<span class="n">mycurve</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pos</span><span class="o">=</span><span class="n">vector</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="o">.</span><span class="n">cyan</span><span class="p">,</span>
<span class="n">radius</span><span class="o">=</span><span class="mf">0.15</span><span class="p">)</span>
<span class="n">mycurve</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pos</span><span class="o">=</span><span class="n">vector</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="o">.</span><span class="n">red</span><span class="p">,</span>
<span class="n">radius</span><span class="o">=</span><span class="mf">0.05</span><span class="p">)</span>
</pre></div>
</div>
<p>The code above produces this:</p>
<img alt="_images/curve_append.png" src="_images/curve_append.png" />
</section>
<section id="advanced-methods-for-modifying-curves">
<h2>Advanced Methods for Modifying Curves<a class="headerlink" href="#advanced-methods-for-modifying-curves" title="Permalink to this heading">¶</a></h2>
<p>All attributes of a point can be combined into a Python dictionary. In Web VPython 3.1 and later dictionaries are supported; earlier versions use a JavaScript object literal, whose syntax is essentially the same as curly bracket form of a Python dictionary.</p>
<p>A Python dict describing a point can be constructed like this:</p>
<p><code class="docutils literal notranslate"><span class="pre">mypoint1=dict(pos=myvector1,</span> <span class="pre">color=mycolor1,</span> <span class="pre">radius=myradius1)</span></code></p>
<p>or like this (same syntax as a JS object literal):</p>
<p><code class="docutils literal notranslate"><span class="pre">mypoint1</span> <span class="pre">=</span> <span class="pre">{'pos':myvector1,</span> <span class="pre">'color':mycolor1,</span> <span class="pre">'radius':myradius1}</span></code></p>
<p>For a curve named “mycurve”:</p>
<ul class="simple">
<li><p>npoints <code class="docutils literal notranslate"><span class="pre">mycurve.npoints</span></code> returns the total number of points in the curve.</p></li>
<li><p>modify() <code class="docutils literal notranslate"><span class="pre">mycurve.modify(N,</span> <span class="pre">pos=mypos,</span> <span class="pre">color=mycolor,</span> <span class="pre">radius=myradius,</span> <span class="pre">visible=True)</span></code> alters the Nth point (the starting point is N=0).</p></li>
<li><p>clear() <code class="docutils literal notranslate"><span class="pre">mycurve.clear()</span></code> removes all points from the curve.</p></li>
<li><p>unshift() <code class="docutils literal notranslate"><span class="pre">mycurve.unshift(</span> <span class="pre">mypointlist</span> <span class="pre">)</span></code> inserts a list of points (dicts) at start of curve.</p></li>
<li><p>splice() <code class="docutils literal notranslate"><span class="pre">mycurve.splice(</span> <span class="pre">N,</span> <span class="pre">howmany,</span> <span class="pre">pointlist)</span></code> inserts a list of points starting at location N.</p></li>
<li><p>pop() <code class="docutils literal notranslate"><span class="pre">mydata</span> <span class="pre">=</span> <span class="pre">mycurve.pop(N)</span></code> return value of point number N and remove it from curve.</p></li>
<li><p>point() <code class="docutils literal notranslate"><span class="pre">mydata</span> <span class="pre">=</span> <span class="pre">mycurve.point(N)</span></code> return Nth point (as a dict).</p></li>
<li><p>slice() <code class="docutils literal notranslate"><span class="pre">mydata</span> <span class="pre">=</span> <span class="pre">mycurve.slice(N1,</span> <span class="pre">N2)</span></code> returns list of points (as dicts) from N1-N2.</p></li>
</ul>
</section>
<section id="color-interpolation-in-curves">
<h2>Color Interpolation in Curves<a class="headerlink" href="#color-interpolation-in-curves" title="Permalink to this heading">¶</a></h2>
<p>The curve machinery interpolates colors from one point to the next. If you want an abrupt change in color, add another point at the same location. In the following example, adding a cyan point at the same location as the orange point makes the first segment be purely cyan.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">c</span> <span class="o">=</span> <span class="n">curve</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="o">.</span><span class="n">cyan</span><span class="p">,</span> <span class="n">radius</span><span class="o">=</span><span class="mf">0.2</span><span class="p">)</span>
<span class="n">c</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">vector</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mf">0.5</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span> <span class="p">)</span>
<span class="c1"># add an extra cyan point:</span>
<span class="n">c</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">vector</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span> <span class="p">)</span>
<span class="c1"># repeat the same point:</span>
<span class="n">c</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">pos</span><span class="o">=</span><span class="n">vector</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>
<span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="o">.</span><span class="n">orange</span> <span class="p">)</span>
<span class="c1"># add another orange point:</span>
<span class="n">c</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">pos</span><span class="o">=</span><span class="n">vector</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mf">0.5</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>
<span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="o">.</span><span class="n">orange</span> <span class="p">)</span>
</pre></div>
</div>
<p>In the image shown here, the upper thick curve, made without the second cyan point, has three pos and color points, cyan, orange, orange, left to right, so the blue fades into the orange. The lower curve includes the extra cyan point and has four pos and color points, cyan, cyan, orange, orange, so there is a sharp break between blue and orange.</p>
<img alt="_images/colors_abutting_small.png" src="_images/colors_abutting_small.png" />
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>Rotation; <a class="reference internal" href="color.html"><span class="doc">color</span></a>; <a class="reference internal" href="emissive.html"><span class="doc">emissive</span></a>; <a class="reference internal" href="canvas.html"><span class="doc">canvas</span></a></p>
</div>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">VPython</a></h1>
<h3>Navigation</h3>
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="objects.html">3D Objects</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="arrow.html">arrow</a></li>
<li class="toctree-l2"><a class="reference internal" href="box.html">box</a></li>
<li class="toctree-l2"><a class="reference internal" href="cone.html">cone</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">curve</a></li>
<li class="toctree-l2"><a class="reference internal" href="cylinder.html">cylinder</a></li>
<li class="toctree-l2"><a class="reference internal" href="ellipsoid.html">ellipsoid</a></li>
<li class="toctree-l2"><a class="reference internal" href="helix.html">helix</a></li>
<li class="toctree-l2"><a class="reference internal" href="label.html">label</a></li>
<li class="toctree-l2"><a class="reference internal" href="points.html">points</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyramid.html">pyramid</a></li>
<li class="toctree-l2"><a class="reference internal" href="ring.html">ring</a></li>
<li class="toctree-l2"><a class="reference internal" href="sphere.html">sphere</a></li>
<li class="toctree-l2"><a class="reference internal" href="text.html">3D text</a></li>
<li class="toctree-l2"><a class="reference internal" href="objects.html#designing-objects">Designing objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="objects.html#delete-an-object">Delete an Object</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="rate.html">Animations</a></li>
<li class="toctree-l1"><a class="reference internal" href="canvas.html">Canvases</a></li>
<li class="toctree-l1"><a class="reference internal" href="cameraAndLights.html">Camera and Lighting</a></li>
<li class="toctree-l1"><a class="reference internal" href="colorOpacityGlow.html">Color/Opacity/Glow</a></li>
<li class="toctree-l1"><a class="reference internal" href="makeshapes.html">Design New Objects</a></li>
<li class="toctree-l1"><a class="reference internal" href="file.html">Files/Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="graph.html">Graphs</a></li>
<li class="toctree-l1"><a class="reference internal" href="math.html">Math Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="workwithobjects.html">Object Attachments</a></li>
<li class="toctree-l1"><a class="reference internal" href="rotation.html">Rotation</a></li>
<li class="toctree-l1"><a class="reference internal" href="textoutput.html">Text output</a></li>
<li class="toctree-l1"><a class="reference internal" href="texture.html">Textures</a></li>
<li class="toctree-l1"><a class="reference internal" href="userinput.html">User Input</a></li>
<li class="toctree-l1"><a class="reference internal" href="webvs7.html">VPython/WebVpython</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">VPython license</a></li>
<li class="toctree-l1"><a class="reference internal" href="resources.html">Additional Resources</a></li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li><a href="objects.html">3D Objects in VPython</a><ul>
<li>Previous: <a href="cone.html" title="previous chapter">cone</a></li>
<li>Next: <a href="cylinder.html" title="next chapter">cylinder</a></li>
</ul></li>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©2023, Ruth Chabay and Bruce Sherwood.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 5.0.2</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
<a href="_sources/curve.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>