vector/de

From Minetest Developer Wiki
Jump to: navigation, search

Tabelle, {x =, y =, z =}

Wird sowohl als Position als auch als Offset in der Minetest API verwendet. Es gibt einige Hilfsfunktionen, die mit Vektoren arbeiten:

Mbox warning.png This page contains unofficial Lua API documentation and is likely to be outdated or wrong.
For the official and up-to-date documentation, refer to lua_api.txt found in your Minetest installation directory under doc.

These functions act on the vector (position) type. For the following functions, v, v1 and v2 are vectors, p1 and p2 are positions and x can either be a vector or a number:

Function Return value Comments
vector.new([x, [y, z]]) vector returns a copy of x, if x is a vector, else a new vector {x=x,y=y,z=z}, or, if every parameter is nil, a vector filled with zeros
vector.direction(p1, p2) vector direction from p1 to p2. the returned vector is normalized. If p1 and p2 are identical, returns {x = 0, y = 0, z = 0}.
vector.distance(p1, p2) number same as vector.length(vector.subtract(p2, p1))
vector.length(v) number returns length of vector. return value is 0 or positive
vector.normalize(v) vector returns vector with length 1 and direction of v
vector.floor(v) vector Returns a vector, each dimension rounded down.
vector.round(v) vector Returns a vector, each dimension rounded to nearest integer.
vector.apply(v, func) vector Returns a vector where the function func has been applied to each component.
vector.equals(v1, v2) bool Returns true if v1 and v2 are identical.
vector.sort(v1, v2) vector, vector Returns in order minp, maxp vectors of the cuboid defined by v1, v2.
vector.angle(v1, v2) number Returns the angle between v1 and v2 in radians.
vector.dot(v1, v2) number Returns the dot product of v1 and v2. See https://en.wikipedia.org/wiki/Dot_product for details.
vector.cross(v1, v2) vector Returns the cross product of v1 and v2. See https://en.wikipedia.org/wiki/Cross_product for details.
vector.add(v, x) vector adds v and x. if x is a number, the operation happens component-wise
vector.subtract(v, x) vector subtracts x from v. if x is a number, the operation happens component-wise
vector.multiply(v, x) vector multiplies v with x. if x is a number, the operation happens component-wise
vector.divide(v, x) vector divides v by x. if x is a number, the operation happens component-wise

Coordinate System

Linke-Hand Koordinaten System(x=rot,y=grün,z=blue)

Minetest verwendet ein linkshändiges Koordinatensystem. Im Weltkoordinatensystem liegt die x-Richtung nach Osten (entsprechend dem Sonnenaufgang), die y-Richtung nach oben und die z-Richtung nach Norden. Im Spieler/Kamera-Koordinatensystem (verwendet z.B. von Player:set_eye_offset() ist die x-Richtung rechts, die y-Richtung oben und die z-Richtung vorne.


Interessanterweise ist die Drehrichtung (wie von Player:get_look_yaw() berichtet, rechtshändig. Der Winkel 0 befindet sich in x-Richtung (Ost), π/2 in z-Richtung (Nord), π in -x-Richtung (West) und 3π/2 in -z- Richtung (Süd).

Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox