matrixdistancefield

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.8, Creation date: 2019-11-24, Last change: 2025-09-14

calculates a matrix distancefield based on a start point and optional end point

Description

There are different methods to calculate the neigborhood mask and the distance
- the distance can be calculated just based on the table distance (1 2 3 4)
- the distance can be calculated based on the value differences (potentials)


See Also: GPLofmatrix , matrixneighbors , matrixvalues

Example Illustration

 missing image of matrixdistancefield(M,st)

Syntax

DM=matrixdistancefield(M,st)

Input Parameter

M: Matrix
st: Start points of value zeros

Output Parameter

DM: Matrix-Distancefield




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

Output

Algorithm Steps

  1. Initialize the distance matrix DM with infinity values, except for NaN values in M, which remain NaN in DM.
  2. Set the distance at the start points st to zero.
  3. Initialize nn as the active points, starting with the start points.
  4. While there are active points (nn is not empty):
    1. For each active point, set its distance in DM to the current distance k.
    2. Find the neighbors of each active point using the matrixneighbors function.
    3. For each neighbor, if it is not NaN and its distance in DM is infinity, set its distance to k+1.
  5. Update nn to the points with distance k+1 using the rcofind function.
  6. Increment k by 1.
  7. 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