Syntax
DM=matrixdistancefield(M,st)
Input Parameter
M : | | Matrix |
st : | | Start points of value zeros |
Output Parameter
Copyright 2019-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This algorithm calculates a matrix distance field based on a start point and optionally an end point. It is designed to work with matrices and uses a breadth-first search approach to determine distances from the start point.
Input Parameters
- M: A matrix representing the field in which distances are calculated.
- st: Start points where the distance is initialized to zero.
Output
- DM: The resulting matrix distance field, where each element represents the distance from the nearest start point.
Algorithm Steps
- Initialize the distance matrix
DM
with infinity values, except for NaN values in M
, which remain NaN in DM
.
- Set the distance at the start points
st
to zero.
- Initialize
nn
as the active points, starting with the start points.
- While there are active points (
nn
is not empty):
- For each active point, set its distance in
DM
to the current distance k
.
- Find the neighbors of each active point using the
matrixneighbors
function.
- For each neighbor, if it is not NaN and its distance in
DM
is infinity, set its distance to k+1
.
- Update
nn
to the points with distance k+1
using the rcofind
function.
- Increment
k
by 1.
- Repeat until no more active points are found.
Visualization
If no output is requested, the algorithm visualizes the distance field using a surface plot with a color bar.
Algorithm explaination created using ChatGPT on 2025-08-19 08:20. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21