Mercurial > pygame
view docs/ref/math.html @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 0a3be7313aa4 |
| children |
line wrap: on
line source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>pygame.math — Pygame v1.9.2 documentation</title> <link rel="stylesheet" href="../_static/pygame.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.9.2', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="shortcut icon" href="../_static/pygame.ico"/> <link rel="top" title="Pygame v1.9.2 documentation" href="../index.html" /> <link rel="next" title="pygame.midi" href="midi.html" /> <link rel="prev" title="pygame.mask" href="mask.html" /> </head> <body> <div class="document"> <div class="header"> <table> <tr> <td class="logo"> <a href="http://www.pygame.org/"> <img src="../_static/pygame_tiny.png"/> </a> <h5>pygame documentation</h5> </td> <td class="pagelinks"> <p class="top"> || <a href="http://www.pygame.org/">Pygame Home</a> || <a href="../index.html">Help Contents</a> || <a href="../genindex.html">Reference Index</a> || </p> <p class="bottom"> <a href="camera.html">camera</a> || <a href="cdrom.html">cdrom</a> || <a href="color.html">Color</a> || <a href="cursors.html">cursors</a> || <a href="display.html">display</a> || <a href="draw.html">draw</a> || <a href="event.html">event</a> || <a href="examples.html">examples</a> || <a href="font.html">font</a> || <a href="freetype.html">freetype</a> || <a href="gfxdraw.html">gfxdraw</a> || <a href="image.html">image</a> || <a href="joystick.html">joystick</a> || <a href="key.html">key</a> || <a href="locals.html">locals</a> || <a href="mask.html">mask</a> || <a href="math.html">math</a> || <a href="midi.html">midi</a> || <a href="mixer.html">mixer</a> || <a href="mouse.html">mouse</a> || <a href="movie.html">movie</a> || <a href="music.html">music</a> || <a href="overlay.html">Overlay</a> || <a href="pixelarray.html">PixelArray</a> || <a href="pixelcopy.html">pixelcopy</a> || <a href="pygame.html">pygame</a> || <a href="rect.html">Rect</a> || <a href="scrap.html">scrap</a> || <a href="sndarray.html">sndarray</a> || <a href="sprite.html">sprite</a> || <a href="surface.html">Surface</a> || <a href="surfarray.html">surfarray</a> || <a href="tests.html">tests</a> || <a href="time.html">time</a> || <a href="transform.html">transform</a> || <a href="pygame.html#module-pygame.version">version</a> </p> </td> </tr> </table> </div> <div class="documentwrapper"> <div class="body"> <div class="sectionwrapper"> <div class="section" id="module-pygame.math"> <span id="pygame-math"></span><dl class="definition module"> <dt class="title module"> <tt class="docutils literal"><span class="pre">pygame.math</span></tt></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">pygame module for vector classes</span></div> </div> <table border="1" class="toc docutils"> <colgroup> <col width="38%" /> <col width="1%" /> <col width="61%" /> </colgroup> <tbody valign="top"> <tr><td><a class="toc reference external" href="math.html#pygame.math.enable_swizzling">pygame.math.enable_swizzling</a></td> <td>—</td> <td>globally enables swizzling for vectors.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.disable_swizzling">pygame.math.disable_swizzling</a></td> <td>—</td> <td>globally disables swizzling for vectors.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2">pygame.math.Vector2</a></td> <td>—</td> <td>a 2-Dimensional Vector</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3">pygame.math.Vector3</a></td> <td>—</td> <td>a 3-Dimensional Vector</td> </tr> </tbody> </table> <p>!!!EXPERIMENTAL!!! Note: This Modul is still in development and the <tt class="docutils literal"><span class="pre">API</span></tt> might change. Please report bug and suggestions to <a class="reference external" href="mailto:pygame-users%40seul.org">pygame-users<span>@</span>seul<span>.</span>org</a></p> <p>The pygame math module currently provides Vector classes in two and three dimensions, Vector2 and Vector3 respectively.</p> <p>They support the following numerical operations: vec+vec, vec-vec, vec*number, number*vec, vec/number, vec//number, vec+=vec, vec-=vec, vec*=number, vec/=number, vec//=number. All these operations will be performed elementwise. In addition vec*vec will perform a scalar-product (a.k.a. dot-product). If you want to multiply every element from vector v with every element from vector w you can use the elementwise method: <tt class="docutils literal"><span class="pre">v.elementwise()</span></tt> <tt class="docutils literal"><span class="pre">\*</span></tt> w</p> <p>New in Pygame 1.10</p> <dl class="definition function"> <dt class="title" id="pygame.math.enable_swizzling"> <tt class="descclassname">pygame.math.</tt><tt class="descname">enable_swizzling</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.enable_swizzling" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">globally enables swizzling for vectors.</span></div> <div class="line"><span class="signature">enable_swizzling() -> None</span></div> </div> <p>Enables swizzling for all vectors until <tt class="docutils literal"><span class="pre">disable_swizzling()</span></tt> is called. By default swizzling is disabled.</p> </dd></dl> <dl class="definition function"> <dt class="title" id="pygame.math.disable_swizzling"> <tt class="descclassname">pygame.math.</tt><tt class="descname">disable_swizzling</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.disable_swizzling" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">globally disables swizzling for vectors.</span></div> <div class="line"><span class="signature">disable_swizzling() -> None</span></div> </div> <p>Disables swizzling for all vectors until <tt class="docutils literal"><span class="pre">enable_swizzling()</span></tt> is called. By default swizzling is disabled.</p> </dd></dl> <dl class="definition class"> <dt class="title" id="pygame.math.Vector2"> <em class="property">class </em><tt class="descclassname">pygame.math.</tt><tt class="descname">Vector2</tt><a class="headerlink" href="#pygame.math.Vector2" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">a 2-Dimensional Vector</span></div> <div class="line"><span class="signature">Vector2() -> Vector2</span></div> <div class="line"><span class="signature">Vector2(Vector2) -> Vector2</span></div> <div class="line"><span class="signature">Vector2(x, y) -> Vector2</span></div> <div class="line"><span class="signature">Vector2((x, y)) -> Vector2</span></div> </div> <table border="1" class="toc docutils"> <colgroup> <col width="37%" /> <col width="1%" /> <col width="62%" /> </colgroup> <tbody valign="top"> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.dot">pygame.math.Vector2.dot</a></td> <td>—</td> <td>calculates the dot- or scalar-product with the other vector</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.cross">pygame.math.Vector2.cross</a></td> <td>—</td> <td>calculates the cross- or vector-product</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.length">pygame.math.Vector2.length</a></td> <td>—</td> <td>returns the euclidic length of the vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.length_squared">pygame.math.Vector2.length_squared</a></td> <td>—</td> <td>returns the squared euclidic length of the vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.normalize">pygame.math.Vector2.normalize</a></td> <td>—</td> <td>returns a vector with the same direction but length 1.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.normalize_ip">pygame.math.Vector2.normalize_ip</a></td> <td>—</td> <td>normalizes the vector in place so that its length is 1.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.is_normalized">pygame.math.Vector2.is_normalized</a></td> <td>—</td> <td>tests if the vector is normalized i.e. has length == 1.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.scale_to_length">pygame.math.Vector2.scale_to_length</a></td> <td>—</td> <td>scales the vector to a given length.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.reflect">pygame.math.Vector2.reflect</a></td> <td>—</td> <td>returns a vector reflected of a given normal.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.reflect_ip">pygame.math.Vector2.reflect_ip</a></td> <td>—</td> <td>reflect the vector of a given normal in place.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.distance_to">pygame.math.Vector2.distance_to</a></td> <td>—</td> <td>calculates the euclidic distance to a given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.distance_squared_to">pygame.math.Vector2.distance_squared_to</a></td> <td>—</td> <td>calculates the squared euclidic distance to a given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.lerp">pygame.math.Vector2.lerp</a></td> <td>—</td> <td>returns a linear interpolation to the given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.slerp">pygame.math.Vector2.slerp</a></td> <td>—</td> <td>returns a spherical interpolation to the given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.elementwise">pygame.math.Vector2.elementwise</a></td> <td>—</td> <td>The next operation will be performed elementwize.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.rotate">pygame.math.Vector2.rotate</a></td> <td>—</td> <td>rotates a vector by a given angle in degrees.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.rotate_ip">pygame.math.Vector2.rotate_ip</a></td> <td>—</td> <td>rotates the vector by a given angle in degrees in place.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.angle_to">pygame.math.Vector2.angle_to</a></td> <td>—</td> <td>calculates the angle to a given vector in degrees.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.as_polar">pygame.math.Vector2.as_polar</a></td> <td>—</td> <td>returns a tuple with radial distance and azimuthal angle.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector2.from_polar">pygame.math.Vector2.from_polar</a></td> <td>—</td> <td>Sets x and y from a polar coordinates tuple.</td> </tr> </tbody> </table> <p>Some general information about the Vector2 class.</p> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.dot"> <tt class="descname">dot</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.dot" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the dot- or scalar-product with the other vector</span></div> <div class="line"><span class="signature">dot(Vector2) -> float</span></div> </div> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.cross"> <tt class="descname">cross</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.cross" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the cross- or vector-product</span></div> <div class="line"><span class="signature">cross(Vector2) -> float</span></div> </div> <p>calculates the third component of the cross-product.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.length"> <tt class="descname">length</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.length" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns the euclidic length of the vector.</span></div> <div class="line"><span class="signature">length() -> float</span></div> </div> <p>calculates the euclidic length of the vector which follows from the Pythagorean theorem: <tt class="docutils literal"><span class="pre">vec.length()</span></tt> == <tt class="docutils literal"><span class="pre">math.sqrt(vec.x**2</span> <span class="pre">+</span> <span class="pre">vec.y**2)</span></tt></p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.length_squared"> <tt class="descname">length_squared</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.length_squared" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns the squared euclidic length of the vector.</span></div> <div class="line"><span class="signature">length_squared() -> float</span></div> </div> <p>calculates the euclidic length of the vector which follows from the Pythagorean theorem: <tt class="docutils literal"><span class="pre">vec.length_squared()</span></tt> == vec.x**2 + vec.y**2 This is faster than <tt class="docutils literal"><span class="pre">vec.length()</span></tt> because it avoids the square root.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.normalize"> <tt class="descname">normalize</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.normalize" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a vector with the same direction but length 1.</span></div> <div class="line"><span class="signature">normalize() -> Vector2</span></div> </div> <p>Returns a new vector that has length == 1 and the same direction as self.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.normalize_ip"> <tt class="descname">normalize_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.normalize_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">normalizes the vector in place so that its length is 1.</span></div> <div class="line"><span class="signature">normalize_ip() -> None</span></div> </div> <p>Normalizes the vector so that it has length == 1. The direction of the vector is not changed.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.is_normalized"> <tt class="descname">is_normalized</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.is_normalized" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">tests if the vector is normalized i.e. has length == 1.</span></div> <div class="line"><span class="signature">is_normalized() -> Bool</span></div> </div> <p>Returns True if the vector has length == 1. Otherwise it returns False.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.scale_to_length"> <tt class="descname">scale_to_length</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.scale_to_length" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">scales the vector to a given length.</span></div> <div class="line"><span class="signature">scale_to_length(float) -> None</span></div> </div> <p>Scales the vector so that it has the given length. The direction of the vector is not changed. You can also scale to length 0. If the vector is the zero vector (i.e. has length 0 thus no direction) an ZeroDivisionError is raised.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.reflect"> <tt class="descname">reflect</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.reflect" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a vector reflected of a given normal.</span></div> <div class="line"><span class="signature">reflect(Vector2) -> Vector2</span></div> </div> <p>Returns a new vector that points in the direction as if self would bounce of a surface characterized by the given surface normal. The length of the new vector is the same as self’s.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.reflect_ip"> <tt class="descname">reflect_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.reflect_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">reflect the vector of a given normal in place.</span></div> <div class="line"><span class="signature">reflect_ip(Vector2) -> None</span></div> </div> <p>Changes the direction of self as if it would have been reflected of a surface with the given surface normal.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.distance_to"> <tt class="descname">distance_to</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.distance_to" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the euclidic distance to a given vector.</span></div> <div class="line"><span class="signature">distance_to(Vector2) -> float</span></div> </div> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.distance_squared_to"> <tt class="descname">distance_squared_to</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.distance_squared_to" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the squared euclidic distance to a given vector.</span></div> <div class="line"><span class="signature">distance_squared_to(Vector2) -> float</span></div> </div> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.lerp"> <tt class="descname">lerp</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.lerp" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a linear interpolation to the given vector.</span></div> <div class="line"><span class="signature">lerp(Vector2, float) -> Vector2</span></div> </div> <p>Returns a Vector which is a linear interpolation between self and the given Vector. The second parameter determines how far between self an other the result is going to be. It must be a value between 0 and 1 where 0 means self an 1 means other will be returned.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.slerp"> <tt class="descname">slerp</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.slerp" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a spherical interpolation to the given vector.</span></div> <div class="line"><span class="signature">slerp(Vector2, float) -> Vector2</span></div> </div> <p>Calculates the spherical interpolation from self to the given Vector. The second argument - often called t - must be in the range [-1, 1]. It parametrizes where - in between the two vectors - the result should be. If a negative value is given the interpolation will not take the complement of the shortest path.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.elementwise"> <tt class="descname">elementwise</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.elementwise" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">The next operation will be performed elementwize.</span></div> <div class="line"><span class="signature">elementwise() -> VectorElementwizeProxy</span></div> </div> <p>Applies the following operation to each element of the vector.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.rotate"> <tt class="descname">rotate</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.rotate" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates a vector by a given angle in degrees.</span></div> <div class="line"><span class="signature">rotate(float) -> Vector2</span></div> </div> <p>Returns a vector which has the same length as self but is rotated counterclockwise by the given angle in degrees.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.rotate_ip"> <tt class="descname">rotate_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.rotate_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates the vector by a given angle in degrees in place.</span></div> <div class="line"><span class="signature">rotate_ip(float) -> None</span></div> </div> <p>Rotates the vector counterclockwise by the given angle in degrees. The length of the vector is not changed.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.angle_to"> <tt class="descname">angle_to</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.angle_to" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the angle to a given vector in degrees.</span></div> <div class="line"><span class="signature">angle_to(Vector2) -> float</span></div> </div> <p>Returns the angle between self and the given vector.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.as_polar"> <tt class="descname">as_polar</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.as_polar" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a tuple with radial distance and azimuthal angle.</span></div> <div class="line"><span class="signature">as_polar() -> (r, phi)</span></div> </div> <p>Returns a tuple (r, phi) where r is the radial distance, and phi is the azimuthal angle.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector2.from_polar"> <tt class="descname">from_polar</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector2.from_polar" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">Sets x and y from a polar coordinates tuple.</span></div> <div class="line"><span class="signature">from_polar((r, phi)) -> None</span></div> </div> <p>Sets x and y from a tuple (r, phi) where r is the radial distance, and phi is the azimuthal angle.</p> </dd></dl> </dd></dl> <dl class="definition class"> <dt class="title" id="pygame.math.Vector3"> <em class="property">class </em><tt class="descclassname">pygame.math.</tt><tt class="descname">Vector3</tt><a class="headerlink" href="#pygame.math.Vector3" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">a 3-Dimensional Vector</span></div> <div class="line"><span class="signature">Vector3() -> Vector3</span></div> <div class="line"><span class="signature">Vector3(Vector3) -> Vector3</span></div> <div class="line"><span class="signature">Vector3(x, y, z) -> Vector3</span></div> <div class="line"><span class="signature">Vector3((x, y, z)) -> Vector3</span></div> </div> <table border="1" class="toc docutils"> <colgroup> <col width="34%" /> <col width="1%" /> <col width="66%" /> </colgroup> <tbody valign="top"> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.dot">pygame.math.Vector3.dot</a></td> <td>—</td> <td>calculates the dot- or scalar-product with the other vector</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.cross">pygame.math.Vector3.cross</a></td> <td>—</td> <td>calculates the cross- or vector-product</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.length">pygame.math.Vector3.length</a></td> <td>—</td> <td>returns the euclidic length of the vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.length_squared">pygame.math.Vector3.length_squared</a></td> <td>—</td> <td>returns the squared euclidic length of the vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.normalize">pygame.math.Vector3.normalize</a></td> <td>—</td> <td>returns a vector with the same direction but length 1.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.normalize_ip">pygame.math.Vector3.normalize_ip</a></td> <td>—</td> <td>normalizes the vector in place so that its length is 1.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.is_normalized">pygame.math.Vector3.is_normalized</a></td> <td>—</td> <td>tests if the vector is normalized i.e. has length == 1.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.scale_to_length">pygame.math.Vector3.scale_to_length</a></td> <td>—</td> <td>scales the vector to a given length.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.reflect">pygame.math.Vector3.reflect</a></td> <td>—</td> <td>returns a vector reflected of a given normal.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.reflect_ip">pygame.math.Vector3.reflect_ip</a></td> <td>—</td> <td>reflect the vector of a given normal in place.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.distance_to">pygame.math.Vector3.distance_to</a></td> <td>—</td> <td>calculates the euclidic distance to a given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.distance_squared_to">pygame.math.Vector3.distance_squared_to</a></td> <td>—</td> <td>calculates the squared euclidic distance to a given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.lerp">pygame.math.Vector3.lerp</a></td> <td>—</td> <td>returns a linear interpolation to the given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.slerp">pygame.math.Vector3.slerp</a></td> <td>—</td> <td>returns a spherical interpolation to the given vector.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.elementwise">pygame.math.Vector3.elementwise</a></td> <td>—</td> <td>The next operation will be performed elementwize.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate">pygame.math.Vector3.rotate</a></td> <td>—</td> <td>rotates a vector by a given angle in degrees.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate_ip">pygame.math.Vector3.rotate_ip</a></td> <td>—</td> <td>rotates the vector by a given angle in degrees in place.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate_x">pygame.math.Vector3.rotate_x</a></td> <td>—</td> <td>rotates a vector around the x-axis by the angle in degrees.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate_x_ip">pygame.math.Vector3.rotate_x_ip</a></td> <td>—</td> <td>rotates the vector around the x-axis by the angle in degrees in place.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate_y">pygame.math.Vector3.rotate_y</a></td> <td>—</td> <td>rotates a vector around the y-axis by the angle in degrees.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate_y_ip">pygame.math.Vector3.rotate_y_ip</a></td> <td>—</td> <td>rotates the vector around the y-axis by the angle in degrees in place.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate_z">pygame.math.Vector3.rotate_z</a></td> <td>—</td> <td>rotates a vector around the z-axis by the angle in degrees.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.rotate_z_ip">pygame.math.Vector3.rotate_z_ip</a></td> <td>—</td> <td>rotates the vector around the z-axis by the angle in degrees in place.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.angle_to">pygame.math.Vector3.angle_to</a></td> <td>—</td> <td>calculates the angle to a given vector in degrees.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.as_spherical">pygame.math.Vector3.as_spherical</a></td> <td>—</td> <td>returns a tuple with radial distance, inclination and azimuthal angle.</td> </tr> <tr><td><a class="toc reference external" href="math.html#pygame.math.Vector3.from_spherical">pygame.math.Vector3.from_spherical</a></td> <td>—</td> <td>Sets x, y and z from a spherical coordinates 3-tuple.</td> </tr> </tbody> </table> <p>Some general information about the Vector3 class.</p> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.dot"> <tt class="descname">dot</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.dot" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the dot- or scalar-product with the other vector</span></div> <div class="line"><span class="signature">dot(Vector3) -> float</span></div> </div> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.cross"> <tt class="descname">cross</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.cross" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the cross- or vector-product</span></div> <div class="line"><span class="signature">cross(Vector3) -> float</span></div> </div> <p>calculates the cross-product.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.length"> <tt class="descname">length</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.length" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns the euclidic length of the vector.</span></div> <div class="line"><span class="signature">length() -> float</span></div> </div> <p>calculates the euclidic length of the vector which follows from the Pythagorean theorem: <tt class="docutils literal"><span class="pre">vec.length()</span></tt> == <tt class="docutils literal"><span class="pre">math.sqrt(vec.x**2</span> <span class="pre">+</span> <span class="pre">vec.y**2</span> <span class="pre">+</span> <span class="pre">vec.z**2)</span></tt></p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.length_squared"> <tt class="descname">length_squared</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.length_squared" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns the squared euclidic length of the vector.</span></div> <div class="line"><span class="signature">length_squared() -> float</span></div> </div> <p>calculates the euclidic length of the vector which follows from the Pythagorean theorem: <tt class="docutils literal"><span class="pre">vec.length_squared()</span></tt> == vec.x**2 + vec.y**2 + vec.z**2 This is faster than <tt class="docutils literal"><span class="pre">vec.length()</span></tt> because it avoids the square root.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.normalize"> <tt class="descname">normalize</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.normalize" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a vector with the same direction but length 1.</span></div> <div class="line"><span class="signature">normalize() -> Vector3</span></div> </div> <p>Returns a new vector that has length == 1 and the same direction as self.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.normalize_ip"> <tt class="descname">normalize_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.normalize_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">normalizes the vector in place so that its length is 1.</span></div> <div class="line"><span class="signature">normalize_ip() -> None</span></div> </div> <p>Normalizes the vector so that it has length == 1. The direction of the vector is not changed.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.is_normalized"> <tt class="descname">is_normalized</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.is_normalized" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">tests if the vector is normalized i.e. has length == 1.</span></div> <div class="line"><span class="signature">is_normalized() -> Bool</span></div> </div> <p>Returns True if the vector has length == 1. Otherwise it returns False.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.scale_to_length"> <tt class="descname">scale_to_length</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.scale_to_length" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">scales the vector to a given length.</span></div> <div class="line"><span class="signature">scale_to_length(float) -> None</span></div> </div> <p>Scales the vector so that it has the given length. The direction of the vector is not changed. You can also scale to length 0. If the vector is the zero vector (i.e. has length 0 thus no direction) an ZeroDivisionError is raised.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.reflect"> <tt class="descname">reflect</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.reflect" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a vector reflected of a given normal.</span></div> <div class="line"><span class="signature">reflect(Vector3) -> Vector3</span></div> </div> <p>Returns a new vector that points in the direction as if self would bounce of a surface characterized by the given surface normal. The length of the new vector is the same as self’s.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.reflect_ip"> <tt class="descname">reflect_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.reflect_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">reflect the vector of a given normal in place.</span></div> <div class="line"><span class="signature">reflect_ip(Vector3) -> None</span></div> </div> <p>Changes the direction of self as if it would have been reflected of a surface with the given surface normal.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.distance_to"> <tt class="descname">distance_to</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.distance_to" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the euclidic distance to a given vector.</span></div> <div class="line"><span class="signature">distance_to(Vector3) -> float</span></div> </div> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.distance_squared_to"> <tt class="descname">distance_squared_to</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.distance_squared_to" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the squared euclidic distance to a given vector.</span></div> <div class="line"><span class="signature">distance_squared_to(Vector3) -> float</span></div> </div> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.lerp"> <tt class="descname">lerp</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.lerp" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a linear interpolation to the given vector.</span></div> <div class="line"><span class="signature">lerp(Vector3, float) -> Vector3</span></div> </div> <p>Returns a Vector which is a linear interpolation between self and the given Vector. The second parameter determines how far between self an other the result is going to be. It must be a value between 0 and 1 where 0 means self an 1 means other will be returned.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.slerp"> <tt class="descname">slerp</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.slerp" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a spherical interpolation to the given vector.</span></div> <div class="line"><span class="signature">slerp(Vector3, float) -> Vector3</span></div> </div> <p>Calculates the spherical interpolation from self to the given Vector. The second argument - often called t - must be in the range [-1, 1]. It parametrizes where - in between the two vectors - the result should be. If a negative value is given the interpolation will not take the complement of the shortest path.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.elementwise"> <tt class="descname">elementwise</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.elementwise" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">The next operation will be performed elementwize.</span></div> <div class="line"><span class="signature">elementwise() -> VectorElementwizeProxy</span></div> </div> <p>Applies the following operation to each element of the vector.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate"> <tt class="descname">rotate</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates a vector by a given angle in degrees.</span></div> <div class="line"><span class="signature">rotate(Vector3, float) -> Vector3</span></div> </div> <p>Returns a vector which has the same length as self but is rotated counterclockwise by the given angle in degrees around the given axis.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate_ip"> <tt class="descname">rotate_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates the vector by a given angle in degrees in place.</span></div> <div class="line"><span class="signature">rotate_ip(Vector3, float) -> None</span></div> </div> <p>Rotates the vector counterclockwise around the given axis by the given angle in degrees. The length of the vector is not changed.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate_x"> <tt class="descname">rotate_x</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate_x" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates a vector around the x-axis by the angle in degrees.</span></div> <div class="line"><span class="signature">rotate_x(float) -> Vector3</span></div> </div> <p>Returns a vector which has the same length as self but is rotated counterclockwise around the x-axis by the given angle in degrees.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate_x_ip"> <tt class="descname">rotate_x_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate_x_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates the vector around the x-axis by the angle in degrees in place.</span></div> <div class="line"><span class="signature">rotate_x_ip(float) -> None</span></div> </div> <p>Rotates the vector counterclockwise around the x-axis by the given angle in degrees. The length of the vector is not changed.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate_y"> <tt class="descname">rotate_y</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate_y" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates a vector around the y-axis by the angle in degrees.</span></div> <div class="line"><span class="signature">rotate_y(float) -> Vector3</span></div> </div> <p>Returns a vector which has the same length as self but is rotated counterclockwise around the y-axis by the given angle in degrees.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate_y_ip"> <tt class="descname">rotate_y_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate_y_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates the vector around the y-axis by the angle in degrees in place.</span></div> <div class="line"><span class="signature">rotate_y_ip(float) -> None</span></div> </div> <p>Rotates the vector counterclockwise around the y-axis by the given angle in degrees. The length of the vector is not changed.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate_z"> <tt class="descname">rotate_z</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate_z" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates a vector around the z-axis by the angle in degrees.</span></div> <div class="line"><span class="signature">rotate_z(float) -> Vector3</span></div> </div> <p>Returns a vector which has the same length as self but is rotated counterclockwise around the z-axis by the given angle in degrees.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.rotate_z_ip"> <tt class="descname">rotate_z_ip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.rotate_z_ip" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">rotates the vector around the z-axis by the angle in degrees in place.</span></div> <div class="line"><span class="signature">rotate_z_ip(float) -> None</span></div> </div> <p>Rotates the vector counterclockwise around the z-axis by the given angle in degrees. The length of the vector is not changed.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.angle_to"> <tt class="descname">angle_to</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.angle_to" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">calculates the angle to a given vector in degrees.</span></div> <div class="line"><span class="signature">angle_to(Vector3) -> float</span></div> </div> <p>Returns the angle between self and the given vector.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.as_spherical"> <tt class="descname">as_spherical</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.as_spherical" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">returns a tuple with radial distance, inclination and azimuthal angle.</span></div> <div class="line"><span class="signature">as_spherical() -> (r, theta, phi)</span></div> </div> <p>Returns a tuple (r, theta, phi) where r is the radial distance, theta is the inclination angle and phi is the azimuthal angle.</p> </dd></dl> <dl class="definition method"> <dt class="title" id="pygame.math.Vector3.from_spherical"> <tt class="descname">from_spherical</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.math.Vector3.from_spherical" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">Sets x, y and z from a spherical coordinates 3-tuple.</span></div> <div class="line"><span class="signature">from_spherical((r, theta, phi)) -> None</span></div> </div> <p>Sets x, y and z from a tuple (r, theta, phi) where r is the radial distance, theta is the inclination angle and phi is the azimuthal angle.</p> </dd></dl> </dd></dl> </dd></dl> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="midi.html" title="pygame.midi" accesskey="N">next</a> |</li> <li class="right" > <a href="mask.html" title="pygame.mask" accesskey="P">previous</a> |</li> <li><a href="../index.html">Pygame v1.9.2 documentation</a> »</li> <script type="text/javascript" src="jquery.plugin.docscomments.js"></script> </ul> </div> <div class="footer"> © Copyright 2011, Pygame Developers. </div> </body> </html>
