Oihana PHP Arango

l2Distance.php

Table of Contents

Functions

l2Distance()  : string
Return the L2 (Euclidean) distance between two vectors.

Functions

l2Distance()

Return the L2 (Euclidean) distance between two vectors.

l2Distance(string|int $x, string|int $y) : string

This helper wraps the ArangoDB AQL function L2_DISTANCE(x, y) which calculates the straight-line distance between two equally-sized numeric vectors (the square root of the sum of the squared component differences). The smaller the value, the closer the vectors are.

Unlike approxNearL2(), this computes the exact distance and does not require (nor benefit from) a vector index.

Example AQL usage:

L2_DISTANCE([1, 2], [4, 6])   // returns 5 (sqrt(3² + 4²))
L2_DISTANCE([0, 0], [0, 0])   // returns 0 (identical vectors)
Parameters
$x : string|int

First input array (vector).

$y : string|int

Second input array (vector).

Tags
example
use function oihana\arango\db\functions\numerics\l2Distance;

$expr = l2Distance('[1, 2]', '[4, 6]');
// Produces: 'L2_DISTANCE([1, 2],[4, 6])'
see
https://docs.arangodb.com/stable/aql/functions/numeric/#l2_distance
l1Distance()

For the Manhattan distance.

since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results