Difference between revisions of "Category:Physics Engine/Vectors"
(Created page with "A vector is a 2-dimensional object with x and y components. Its type is TI.cpVect. Category:Physics_Engine") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
A vector is a 2-dimensional object with x and y components. Its type is TI.cpVect. | A vector is a 2-dimensional object with x and y components. Its type is TI.cpVect. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Vect ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">vector = physics.Vect(x, y) | ||
+ | vector = physics.Vect(angle) | ||
+ | vector = physics.Vect(vect) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | x | ||
+ | | '''in''' number | ||
+ | | The _x_ component of the vector | ||
+ | |- | ||
+ | | y | ||
+ | | '''in''' number | ||
+ | | The _y_ component of the vector | ||
+ | |- | ||
+ | | angle | ||
+ | | '''in''' number | ||
+ | | An angle in radians | ||
+ | |- | ||
+ | | vect | ||
+ | | '''in''' physics.Vect | ||
+ | | A vector | ||
+ | |- | ||
+ | | vector | ||
+ | | '''out''' physics.Vect | ||
+ | | A vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Creates a vector with initial x and y component values. The second form creates a unit vector pointing in direction ''angle''. The third form creates a copy of the input vector. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== add ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">sum = physics.Vect:add(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | A vector to add to ''self'' | ||
+ | |- | ||
+ | | sum | ||
+ | | '''out''' physics.Vect | ||
+ | | The vector sum of ''self'' and ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the vector sum of ''self'' and ''vec''. | ||
+ | |||
+ | The Vect class also implements the addition operator (+). Therefore vectors ''v1'' and ''v2'' can be added with the expression ''v1'' + ''v2''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== clamp ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">clamped = physics.Vect:clamp(len) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | len | ||
+ | | '''in''' number | ||
+ | | The maximum length of the vector | ||
+ | |- | ||
+ | | clamped | ||
+ | | '''out''' physics.Vect | ||
+ | | A new vector with a length no longer than ''len'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns a copy of ''self'' clamped to length ''len''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== cross ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">crossprod = physics.Vect:cross(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The vector to cross with ''self'' | ||
+ | |- | ||
+ | | zmag | ||
+ | | '''out''' number | ||
+ | | The z magnitude of the cross product of ''self'' and ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the z magnitude of the cross product of ''self'' and ''vec''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== dist ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">dist = physics.Vect:dist(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The vector to which to find the distance from ''self'' | ||
+ | |- | ||
+ | | dist | ||
+ | | '''out''' number | ||
+ | | The distance from ''self'' to ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the distance between ''self'' and ''vec''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== distsq ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">distsq = physics.Vect:distsq(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The vector to which to find the distance squared from ''self'' | ||
+ | |- | ||
+ | | distsq | ||
+ | | '''out''' number | ||
+ | | The distance squared from ''self'' to ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the distance squared between ''self'' and ''vec''. This routine is faster than physics.Vect:dist when you only need to compare distances. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== dot ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">dotprod = physics.Vect:dot(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other vector | ||
+ | |- | ||
+ | | dotprod | ||
+ | | '''out''' number | ||
+ | | The scalar dot product of ''self'' and ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the scalar dot product of ''self'' and ''vec''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== eql ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">isequ = physics.Vect:eql(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The vector against which to compare with ''self'' | ||
+ | |- | ||
+ | | isequ | ||
+ | | '''out''' boolean | ||
+ | | True if the components of ''self'' equal the components of ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns true if the x and y components of ''self'' equal those of ''vec''. Take the usual precautions when comparing floating point numbers for equality. | ||
+ | |||
+ | The Vect class also implements the equal comparison operator (==). Therefore vectors ''v1'' and ''v2'' can be compared with the expression ''v1'' == ''v2''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== length ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">len = physics.Vect:length() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | len | ||
+ | | '''out''' number | ||
+ | | The length of vector ''self'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the magnitude of ''self''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== lengthsq ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">lensq = physics.Vect:lengthsq() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | lensq | ||
+ | | '''out''' number | ||
+ | | The length squared of vector ''self'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the length squared of ''self''. This routine is faster than Vect:length() when you only need to compare lengths. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== lerp ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">v = physics.Vect:lerp(vec, f) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other vector | ||
+ | |- | ||
+ | | f | ||
+ | | '''in''' number | ||
+ | | ''f_ is a fractional number from 0 to 1 representing the proportion of distance between _self'' and ''vec'' | ||
+ | |- | ||
+ | | v | ||
+ | | '''out''' physics.Vect | ||
+ | | A vector interpolated between ''self'' and ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the linear interpolation between ''self'' and ''vec'' as a vector. ''f_ is the fraction of distance between _self'' and ''vec''. | ||
+ | <div style="white-space: pre"> | ||
+ | May not behave as expected for f larger than 1.0 or less than 0. | ||
+ | </div> | ||
+ | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#FFFFCE;" | ||
+ | |} | ||
+ | |||
+ | <br> | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== lerpconst ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">v = physics.Vect:lerpconst(vec, d) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other vector | ||
+ | |- | ||
+ | | d | ||
+ | | '''in''' number | ||
+ | | The distance from ''self'' to ''vec'' to interpolate a new vector | ||
+ | |- | ||
+ | | v | ||
+ | | '''out''' physics.Vect | ||
+ | | | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns a vector interpolated from ''self'' towards ''vec'' with length _d_. | ||
+ | <div style="white-space: pre"> | ||
+ | May not behave as expected for d larger than 1.0 or less than 0. | ||
+ | </div> | ||
+ | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#FFFFCE;" | ||
+ | |} | ||
+ | |||
+ | <br> | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== mult ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">v = physics.Vect:mult(factor) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | factor | ||
+ | | '''in''' number | ||
+ | | The value to multiply by ''self'' | ||
+ | |- | ||
+ | | v | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting scaled vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Multiplies a vector by a factor. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== near ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">isnear = physics.Vect:near(vec, distance) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The value to multiply by ''self'' | ||
+ | |- | ||
+ | | distance | ||
+ | | '''in''' number | ||
+ | | The distance from ''vec'' | ||
+ | |- | ||
+ | | isnear | ||
+ | | '''out''' boolean | ||
+ | | True if ''self'' is within ''distance'' of ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Determines if ''self'' is near another vector. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== neg ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">v = physics.Vect:neg() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | v | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting negated vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the negative of ''self''. | ||
+ | |||
+ | The Vect class also implements the unary minus operator (<nowiki>-</nowiki>''self''). | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <br> | ||
+ | |||
+ | ===== normalize ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">normvec = physics.Vect:normalize() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | normvec | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting normalized vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns a normalized copy of ''self''. The length of a normal vector is 1. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== normalizeSafe ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">normvec = physics.Vect:normalizeSafe() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | normvec | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting normalized vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns a normalized copy of ''self''. Protects against division by zero. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== perp ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">perpvec = physics.Vect:perp() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | perpvec | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting perpendicular vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns a vector perpendicular to ''self''. (90 degree rotation) | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== project ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">pvec = physics.Vect:project(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other vector | ||
+ | |- | ||
+ | | pvec | ||
+ | | '''out''' physics.Vect | ||
+ | | The vector of ''self'' projected onto ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Computes the projection of ''self'' onto another vector. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== rotate ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">rvec = physics.Vect:rotate(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other vector | ||
+ | |- | ||
+ | | rvec | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting rotated vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Uses complex multiplication to rotate ''self'' by ''vec''. Scaling will occur if ''self'' is not a unit vector. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== rperp ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">perpvec = physics.Vect:rperp() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | perpvec | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting perpendicular vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns a vector perpendicular to ''self''. (90 degree rotation) | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== setx ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">self = physics.Vect:setx(x) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The vector to modify | ||
+ | |- | ||
+ | | x | ||
+ | | '''in''' number | ||
+ | | The new value of the _x_ component of the vector | ||
+ | |- | ||
+ | | self | ||
+ | | '''out''' physics.Vect | ||
+ | | The input vector is returned as the output | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Changes the value of the ''x_ component of _self''. Returns ''self''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== sety ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">self = physics.Vect:sety(y) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The vector to modify | ||
+ | |- | ||
+ | | y | ||
+ | | '''in''' number | ||
+ | | The new value of the _y_ component of the vector | ||
+ | |- | ||
+ | | self | ||
+ | | '''out''' physics.Vect | ||
+ | | The input vector is returned as the output | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Changes the value of the ''y_ component of _self''. Returns ''self''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== slerp ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">v = physics.Vect:slerp(vec, f) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | A unit vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other unit vector | ||
+ | |- | ||
+ | | f | ||
+ | | '''in''' number | ||
+ | | ''f_ is a fractional number from 0 to 1 representing the proportion of distance between _self'' and ''vec'' | ||
+ | |- | ||
+ | | v | ||
+ | | '''out''' physics.Vect | ||
+ | | A vector interpolated between ''self'' and ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Computes a spherical linear interpolation between unit vectors ''self'' and ''vec''. | ||
+ | <div style="white-space: pre"> | ||
+ | See [[http://en.wikipedia.org/wiki/Slerp http://en.wikipedia.org/wiki/Slerp]] for a discussion of the meaning, value, and usage of spherical linear interpolation. | ||
+ | </div> | ||
+ | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | <br> <!-- code start--> | ||
+ | |||
+ | ===== slerp ===== | ||
+ | |||
+ | ---- | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">local vect1 = physics.Vect(math.pi/3) -- unit vector with angle pi/3 radians | ||
+ | local vect2 = physics.Vect(math.pi/2) -- unit vector with angle pi/2 radians | ||
+ | local result = vect1:slerp(vect2, 0.55) -- compute spherical linear interpolation | ||
+ | </pre><!-- code end--> <div style="white-space: pre"> | ||
+ | This routine computes meaningful results only when the two inputs are unit vectors. | ||
+ | |||
+ | May not behave as expected for f larger than 1.0 or less than 0. | ||
+ | |||
+ | |||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | </div> | ||
+ | ---- | ||
+ | |||
+ | ===== slerpconst ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">v = physics.Vect:slerpconst(vec, angle) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | A unit vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other unit vector | ||
+ | |- | ||
+ | | angle | ||
+ | | '''in''' number | ||
+ | | The maximum angle between ''self'' and ''vec'' to interpolate a new vector | ||
+ | |- | ||
+ | | v | ||
+ | | '''out''' physics.Vect | ||
+ | | | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the spherical linear interpolation from ''self'' towards ''vec'' but by no more than ''angle'' in radians. | ||
+ | <div style="white-space: pre"> | ||
+ | See [[http://en.wikipedia.org/wiki/Slerp http://en.wikipedia.org/wiki/Slerp]] for a discussion of the meaning, value, and usage of spherical linear interpolation. | ||
+ | </div> | ||
+ | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
+ | |} | ||
+ | |||
+ | <br> | ||
+ | <div style="white-space: pre"> | ||
+ | This routine computes meaningful results only when the two inputs are unit vectors. | ||
+ | </div> | ||
+ | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#FFFFCE;" | ||
+ | |- | ||
+ | | <span style="color:#AAAA00">'''NOTE''':</span> '''NOTE''' | ||
+ | ---- | ||
+ | |||
+ | |} | ||
+ | |||
+ | <br> | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== sub ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">diff = physics.Vect:sub(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | A vector to subtract from ''self'' | ||
+ | |- | ||
+ | | diff | ||
+ | | '''out''' physics.Vect | ||
+ | | The vector difference between ''self'' and ''vec'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the vector difference of ''self'' and ''vec''. | ||
+ | |||
+ | The Vect class also implements the subtraction operator (-). Therefore vector ''v2'' can be subtracted from ''v1'' with the expression ''v1'' <nowiki>-</nowiki> ''v2''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== toangle ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">angle = physics.Vect:toangle() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | angle | ||
+ | | '''out''' number | ||
+ | | The angle of ''self'' | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the angle in radians of ''self''. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== unrotate ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">uvec = physics.Vect:unrotate(vec) | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | vec | ||
+ | | '''in''' physics.Vect | ||
+ | | The other vector | ||
+ | |- | ||
+ | | uvec | ||
+ | | '''out''' physics.Vect | ||
+ | | The resulting unrotated vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Inverse of physics.Vect:rotate(vec). | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== x ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">x = physics.Vect:x() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | x | ||
+ | | '''out''' number | ||
+ | | The value of the _x_ component of the vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the value of the _x_ component of the input vector. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== y ===== | ||
+ | |||
+ | <!-- code start--> | ||
+ | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd">y = physics.Vect:y() | ||
+ | </pre><!-- code end--> <!-- table start --> | ||
+ | {| border="1" width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable sortable" | ||
+ | |- | ||
+ | ! Parameter | ||
+ | ! Type | ||
+ | ! Description <!-- header row end --> | ||
+ | |- | ||
+ | | self | ||
+ | | '''in''' physics.Vect | ||
+ | | The input vector | ||
+ | |- | ||
+ | | y | ||
+ | | '''out''' number | ||
+ | | The value of the _y_ component of the vector | ||
+ | |} | ||
+ | <!-- table end --> | ||
+ | <br> Returns the value of the _y_ component of the input vector. | ||
+ | |||
+ | Introduced in platform.apiLevel = '2.0' | ||
[[Category:Physics_Engine]] | [[Category:Physics_Engine]] |
Latest revision as of 08:16, 18 July 2012
A vector is a 2-dimensional object with x and y components. Its type is TI.cpVect.
Contents
Vect
vector = physics.Vect(x, y) vector = physics.Vect(angle) vector = physics.Vect(vect)
Parameter | Type | Description |
---|---|---|
x | in number | The _x_ component of the vector |
y | in number | The _y_ component of the vector |
angle | in number | An angle in radians |
vect | in physics.Vect | A vector |
vector | out physics.Vect | A vector |
Creates a vector with initial x and y component values. The second form creates a unit vector pointing in direction angle. The third form creates a copy of the input vector.
Introduced in platform.apiLevel = '2.0'
add
sum = physics.Vect:add(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | A vector to add to self |
sum | out physics.Vect | The vector sum of self and vec |
Returns the vector sum of self and vec.
The Vect class also implements the addition operator (+). Therefore vectors v1 and v2 can be added with the expression v1 + v2.
Introduced in platform.apiLevel = '2.0'
clamp
clamped = physics.Vect:clamp(len)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
len | in number | The maximum length of the vector |
clamped | out physics.Vect | A new vector with a length no longer than len |
Returns a copy of self clamped to length len.
Introduced in platform.apiLevel = '2.0'
cross
crossprod = physics.Vect:cross(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The vector to cross with self |
zmag | out number | The z magnitude of the cross product of self and vec |
Returns the z magnitude of the cross product of self and vec.
Introduced in platform.apiLevel = '2.0'
dist
dist = physics.Vect:dist(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The vector to which to find the distance from self |
dist | out number | The distance from self to vec |
Returns the distance between self and vec.
Introduced in platform.apiLevel = '2.0'
distsq
distsq = physics.Vect:distsq(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The vector to which to find the distance squared from self |
distsq | out number | The distance squared from self to vec |
Returns the distance squared between self and vec. This routine is faster than physics.Vect:dist when you only need to compare distances.
Introduced in platform.apiLevel = '2.0'
dot
dotprod = physics.Vect:dot(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The other vector |
dotprod | out number | The scalar dot product of self and vec |
Returns the scalar dot product of self and vec.
Introduced in platform.apiLevel = '2.0'
eql
isequ = physics.Vect:eql(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The vector against which to compare with self |
isequ | out boolean | True if the components of self equal the components of vec |
Returns true if the x and y components of self equal those of vec. Take the usual precautions when comparing floating point numbers for equality.
The Vect class also implements the equal comparison operator (==). Therefore vectors v1 and v2 can be compared with the expression v1 == v2.
Introduced in platform.apiLevel = '2.0'
length
len = physics.Vect:length()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
len | out number | The length of vector self |
Returns the magnitude of self.
Introduced in platform.apiLevel = '2.0'
lengthsq
lensq = physics.Vect:lengthsq()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
lensq | out number | The length squared of vector self |
Returns the length squared of self. This routine is faster than Vect:length() when you only need to compare lengths.
Introduced in platform.apiLevel = '2.0'
lerp
v = physics.Vect:lerp(vec, f)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The other vector |
f | in number | f_ is a fractional number from 0 to 1 representing the proportion of distance between _self and vec |
v | out physics.Vect | A vector interpolated between self and vec |
Returns the linear interpolation between self and vec as a vector. f_ is the fraction of distance between _self and vec.
May not behave as expected for f larger than 1.0 or less than 0.
Introduced in platform.apiLevel = '2.0'
lerpconst
v = physics.Vect:lerpconst(vec, d)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The other vector |
d | in number | The distance from self to vec to interpolate a new vector |
v | out physics.Vect |
Returns a vector interpolated from self towards vec with length _d_.
May not behave as expected for d larger than 1.0 or less than 0.
Introduced in platform.apiLevel = '2.0'
mult
v = physics.Vect:mult(factor)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
factor | in number | The value to multiply by self |
v | out physics.Vect | The resulting scaled vector |
Multiplies a vector by a factor.
Introduced in platform.apiLevel = '2.0'
near
isnear = physics.Vect:near(vec, distance)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The value to multiply by self |
distance | in number | The distance from vec |
isnear | out boolean | True if self is within distance of vec |
Determines if self is near another vector.
Introduced in platform.apiLevel = '2.0'
neg
v = physics.Vect:neg()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
v | out physics.Vect | The resulting negated vector |
Returns the negative of self.
The Vect class also implements the unary minus operator (-self).
Introduced in platform.apiLevel = '2.0'
normalize
normvec = physics.Vect:normalize()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
normvec | out physics.Vect | The resulting normalized vector |
Returns a normalized copy of self. The length of a normal vector is 1.
Introduced in platform.apiLevel = '2.0'
normalizeSafe
normvec = physics.Vect:normalizeSafe()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
normvec | out physics.Vect | The resulting normalized vector |
Returns a normalized copy of self. Protects against division by zero.
Introduced in platform.apiLevel = '2.0'
perp
perpvec = physics.Vect:perp()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
perpvec | out physics.Vect | The resulting perpendicular vector |
Returns a vector perpendicular to self. (90 degree rotation)
Introduced in platform.apiLevel = '2.0'
project
pvec = physics.Vect:project(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The other vector |
pvec | out physics.Vect | The vector of self projected onto vec |
Computes the projection of self onto another vector.
Introduced in platform.apiLevel = '2.0'
rotate
rvec = physics.Vect:rotate(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The other vector |
rvec | out physics.Vect | The resulting rotated vector |
Uses complex multiplication to rotate self by vec. Scaling will occur if self is not a unit vector.
Introduced in platform.apiLevel = '2.0'
rperp
perpvec = physics.Vect:rperp()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
perpvec | out physics.Vect | The resulting perpendicular vector |
Returns a vector perpendicular to self. (90 degree rotation)
Introduced in platform.apiLevel = '2.0'
setx
self = physics.Vect:setx(x)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The vector to modify |
x | in number | The new value of the _x_ component of the vector |
self | out physics.Vect | The input vector is returned as the output |
Changes the value of the x_ component of _self. Returns self.
Introduced in platform.apiLevel = '2.0'
sety
self = physics.Vect:sety(y)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The vector to modify |
y | in number | The new value of the _y_ component of the vector |
self | out physics.Vect | The input vector is returned as the output |
Changes the value of the y_ component of _self. Returns self.
Introduced in platform.apiLevel = '2.0'
slerp
v = physics.Vect:slerp(vec, f)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | A unit vector |
vec | in physics.Vect | The other unit vector |
f | in number | f_ is a fractional number from 0 to 1 representing the proportion of distance between _self and vec |
v | out physics.Vect | A vector interpolated between self and vec |
Computes a spherical linear interpolation between unit vectors self and vec.
See [http://en.wikipedia.org/wiki/Slerp] for a discussion of the meaning, value, and usage of spherical linear interpolation.
slerp
local vect1 = physics.Vect(math.pi/3) -- unit vector with angle pi/3 radians local vect2 = physics.Vect(math.pi/2) -- unit vector with angle pi/2 radians local result = vect1:slerp(vect2, 0.55) -- compute spherical linear interpolation
This routine computes meaningful results only when the two inputs are unit vectors.
May not behave as expected for f larger than 1.0 or less than 0.
Introduced in platform.apiLevel = '2.0'
slerpconst
v = physics.Vect:slerpconst(vec, angle)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | A unit vector |
vec | in physics.Vect | The other unit vector |
angle | in number | The maximum angle between self and vec to interpolate a new vector |
v | out physics.Vect |
Returns the spherical linear interpolation from self towards vec but by no more than angle in radians.
See [http://en.wikipedia.org/wiki/Slerp] for a discussion of the meaning, value, and usage of spherical linear interpolation.
This routine computes meaningful results only when the two inputs are unit vectors.
NOTE: NOTE
|
Introduced in platform.apiLevel = '2.0'
sub
diff = physics.Vect:sub(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | A vector to subtract from self |
diff | out physics.Vect | The vector difference between self and vec |
Returns the vector difference of self and vec.
The Vect class also implements the subtraction operator (-). Therefore vector v2 can be subtracted from v1 with the expression v1 - v2.
Introduced in platform.apiLevel = '2.0'
toangle
angle = physics.Vect:toangle()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
angle | out number | The angle of self |
Returns the angle in radians of self.
Introduced in platform.apiLevel = '2.0'
unrotate
uvec = physics.Vect:unrotate(vec)
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
vec | in physics.Vect | The other vector |
uvec | out physics.Vect | The resulting unrotated vector |
Inverse of physics.Vect:rotate(vec).
Introduced in platform.apiLevel = '2.0'
x
x = physics.Vect:x()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
x | out number | The value of the _x_ component of the vector |
Returns the value of the _x_ component of the input vector.
Introduced in platform.apiLevel = '2.0'
y
y = physics.Vect:y()
Parameter | Type | Description |
---|---|---|
self | in physics.Vect | The input vector |
y | out number | The value of the _y_ component of the vector |
Returns the value of the _y_ component of the input vector.
Introduced in platform.apiLevel = '2.0'
This category currently contains no pages or media.