# Spatial Vectors

From Minetest Developer Wiki

(Redirected from Vector helpers)

These functions act on the vector (position) type.

Function | Return value | Comments |
---|---|---|

vector.new([x, [y, z]]) | vector | x can be either be a vector or the position x of the new vector (requires x and y to be set too) |

vector.direction(p1, p2) | vector | direction from p1 to p2, maximal values are: {x=-1,y=-1,z=-1} and {x=1,y=1,z=1} |

vector.distance(p1, p2) | number | same as vector.length(vector.subtract(p2, p1)) |

vector.length(v) | number | |

vector.normalize(v) | vector | |

vector.round(v) | vector | same as vector.apply(v, function(c) return math.floor(c + 0.5) end) |

vector.equals(v1, v2) | bool | |

vector.add(v, x) | vector | x can be either a vector or a number. |

vector.subtract(v, x) | vector | x can be either a vector or a number. same as vector.add(v, -x) or vector.add(v, vector.multiply(x, -1)) |

vector.multiply(v, x) | vector | x can be either a vector or a number. |

vector.divide(v, x) | vector | x can be either a vector or a number. |