voxofcart

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - VM/Voxels
Introduced first in SolidGeometry 2.1, Creation date: 2015-01-12, Last change: 2025-09-14

returns voxel coordinates from cartesian coordinates



See Also: cartofvox

Example Illustration

 missing image of voxofcart(vs,p)

Syntax

vox=voxofcart(vs,p)

Input Parameter

vs: voxel size [bx by bz]
p: cartesian coordinate vector

Output Parameter

vox: voxel coordinate vector

Examples


voxofcart([1 1 1],[2.4 2.4 1])
cartofvox([0.2 0.2 1],[2 2 1])




Copyright 2015-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 function, voxofcart, converts Cartesian coordinates to voxel coordinates. It is part of the SolidGeometry library and was introduced by Tim Lueth in 2015.

Input Parameters

Output

Algorithm Explanation

The function calculates the voxel coordinates by performing the following steps:

  1. Divide each component of the Cartesian coordinate vector p by the corresponding component of the voxel size vector vs. This is done for each dimension (x, y, z).
  2. Add 1.5 to each of the resulting values. This step is likely used to ensure proper rounding when converting to integer voxel coordinates.
  3. Apply the floor function to each of the adjusted values. The floor function rounds each value down to the nearest integer, effectively converting the adjusted Cartesian coordinates to voxel coordinates.

Example

For example, calling voxofcart([1 1 1],[2.4 2.4 1]) will return the voxel coordinates by dividing each component of the Cartesian coordinates by the voxel size, adding 1.5, and then flooring the result.

Algorithm explaination created using ChatGPT on 2025-08-18 22:10. (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