Repository navigation
Expand file tree
/
Copy pathcompound.html
More file actions
86 lines (84 loc) · 9.14 KB
/
Copy pathcompound.html
File metadata and controls
86 lines (84 loc) · 9.14 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
<!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" --><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>compound</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: x-large}
.style2 {font-size: xx-large}
-->
</style>
<!-- InstanceEndEditable -->
</head>
<body>
<div id="wrapper">
<div id="leftmenu">
<p class="Normal"><a href="index.html"> Home</a></p>
<p class="Normal"> <a href="VisualIntro.html">Overview of Python & VPython<br>
</a></p>
<p class="Normal"><a href="https://trinket.io/matter-interactions/courses/00_welcome_to_vpython#/welcome-to-vpython/getting-started"> "Welcome to VPython" tutorial</a></p>
<p class="Normal"><a href="videos.html"> Introductory Videos</a></p>
<p class="Normal"><a href="primitives.html"> Pictures</a> of 3D objects</p>
<p> <select id="menu1" onChange="jumpMenu(this)"></select></p>
<p> <select id="menu2" onChange="jumpMenu(this)"></select></p>
<p> <select id="menu3" onChange="jumpMenu(this)"></select></p>
<p class="Normal"><a href="https://vpython.org" target="_blank"> VPython 7 web site</a><br />
<a href="license.txt" target="_blank"> VPython license</a><br />
<br />
</p>
</td>
</div>
<div id="content">
<!-- InstanceBeginEditable name="content" -->
<div>
<table width="100%" border="1">
<tr>
<td width="78%"><div align="center"><span class="style1 style2"><font color="#0000A0">compound</font></span></div></td>
<td width="22%"><div align="center"><img src="images/compound.jpg" alt="ring" width="137" height="138" /><a href="arrow.html"></a></div></td>
</tr>
</table>
</div>
<div>
<p class="Normal">The <strong>compound</strong> object lets you group objects together and manage them as though they were one object, by specifying in the usual way <span class="attribute">pos</span>, <span class="attribute">color</span>, <span class="attribute">size</span> (or <span class="attribute">length</span>, <span class="attribute">width</span>, <span class="attribute">height</span>), <span class="attribute">axis</span>, <span class="attribute">up</span>, <span class="attribute">opacity</span>, <span class="attribute">shininess</span>, <span class="attribute">emissive</span>, and <span class="attribute">texture</span>. Moreover, the display of a complicated compound object is faster than displaying the individual objects one at a time. (In Web VPython version 2.1 the <strong><a href="compound2.1.html" target="_blank">details were somewhat different</a></strong>.)</p>
<p class="Normal">The object shown above is a compound of a cylinder and a box:</p>
<p class="program">handle = cylinder( size=vector(1,.2,.2), <br>
color=vector(0.72,0.42,0) )<br />
<br />
head = box( size=vector(.2,.6,.2), pos=vector(1.1,0,0), c<br>
color=color.gray(.6) )<br />
<br />
hammer = compound([handle, head])<br />
hammer.axis = vector(1,1,0)</p>
<p class="Normal"><strong>The size of the object:</strong> After creating the compound named "hammer", <strong>hammer.size</strong> represents the size of the xyz bounding box of the object. The x, y, and z components of hammer.size can also be referred to as hammer.length, hammer.height, and hammer.width.</p>
<p class="Normal"><strong>The position of the compound</strong> is <strong>hammer.pos</strong>: After creating the compound, <strong>hammer.pos</strong> is located at the center of the bounding box. Later changes to hammer.pos move the center of the compound object to a new location.</p>
<p class="Normal"><strong>No linkage of axis and size:</strong> After creating the hammer as a compound object, changing the axis rotates the combined object. Changing the axis does not affect the size.</p>
<p class="Normal"><strong>Invisible objects are included:</strong> All objects in the list become part of the compound, even if they have visible = False. It is as though all the objects have visible set to True.</p>
<p class="Normal"> The individual objects in a compound are "frozen". You can't change their attributes such as positions or orientations except as a group. </p>
<p class="Normal"><strong><font color="#0000a0">Color blending</font></strong></p>
<p class="Normal">Setting <strong>hammer.color</strong> to something other than white makes a multiplicative blend of the overall color with the colors of the individual objects. For example, if the color of the handle is cyan, vector(0,1,1), and the hammer color is yellow, vector(1,1,0), the blend results in vector(0*1, 1*1, 0*0) or vector(0,1,0), which is green. If you plan to vary the color after creating the compound object, start with the color being white, vector(1,1,1), which is the default.</p>
<p class="Normal"><strong><font color="#0000a0">Specifying an origin</font></strong></p>
<p class="Normal">As mentioned above, after creating a compound its position (pos) is at the center of the bounding box that encloses all the pieces of the compound. Sometimes it is convenient for pos to be somewhere else in the compound, such as at the left end or even outside the bounding box. When creating a compound you can optionally specify a different location by setting the "origin", as in "compound([....] origin=vec(x,y,z))". This sets the initial pos of the compound to the origin, and when you move the compound by changing pos, origin doesn't change, thereby preserving a record of the original choice of origin.</p>
<p class="Normal"><strong><font color="#0000a0">Setting parameters when creating a compound</font></strong></p>
<p class="Normal">You can optionally specify parameters to be applied to a compound after its creation. The following statement is equivalent to creating the hammer, then changing the position and axis, where the resulting center of the compound will be at vector(3,2,0):</p>
<p class="program">hammer = compound( [handle, head], pos=vector(3,2,0),<br />
axis=vector(1,1,0) )</p>
<p class="Normal">If you specify an origin, that sets the default pos value, which is then changed if you also specify a value for pos when creating the compound.</p>
<p class="Normal">All of the objects to be compounded must belong to the same canvas, and the compound itself must also be in this canvas. Also, it is currently not possible to clone a compound to a different canvas.</p>
<p class="Normal"><strong><font color="#0000a0">Compound and world coordinates</font></strong></p>
<p class="Normal"> There are two functions for translating between compound and world coordinates, which may differ if the compound object has been moved or rotated or resized. Suppose when you created the compound <strong>c</strong> a location on one of the objects was the vector <strong>v</strong>, and that after moving, rotating, and resizing the compound you would like to know where that point is now. In the following, <strong>world_pos</strong> is the corresponding location in "world" coordinates, the actual location in the current 3D scene:</p>
<p class="program">world_pos = c.compound_to_world(v) </p>
<p class="Normal">You can go the other way, from world coordinates to the coordinates at the time you created the compound. The following will display the value of the vector <strong>v</strong>:</p>
<p class="program">print( c.world_to_compound(world_pos) )</p>
<p class="Normal"><strong><font color="#0000a0">Current restrictions</font></strong></p>
<p class="Normal">Currently objects in a compound can have their own values of <strong>color</strong>, <strong>opacity</strong>, <strong>shininess</strong>, and <strong>emissive</strong>, but they cannot have individual textures or bumpmaps, which can only be specified for the combined object, and which affect all of the compounded objects.</p>
<p class="Normal">Currently label objects, lights, and objects based on curve objects (curve, helix) cannot be compounded. However, <a href="triangle.html">triangles</a>, <a href="triangle.html">quads</a>, and even other compounds can be compounded. Also, a compound object can be <a href="clone.html">cloned</a> to make additional copies.</p>
<p> </p>
<!-- InstanceEndEditable -->
</div>
</div>
</body>
<script type="text/javascript" language="javascript" src="navigation.js"></script>
<!-- InstanceEnd --></html>