VLnorm

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 1.0, Creation date: 2012-07-10, Last change: 2025-09-14

returns the list of all normalized vectors and the norm length for a given vector list

Description

Version 4.0 is 10-20 times faster than version 3.9 using normr! and vectnorm
Attention normr returns a unit vector [1 1 1]/sqrt(dim) instead of [0 0 0] for a vector of length(0). This function corrects it, since it returns additional information.
This is the maximum speed function that I achieved. Using bsxfun instead of a loop with the norm function was NOT faster, but slightly slower. The division time is negligible in comparison with norm. So if the norm is calculated, is makes sense also to calculate the normalized vector, even the order of the output parameters is not optimal, i.e. should be exchanged

See Also: , VLdistance , VLunidirect , PLnorm , PLELnorm , PLFLfaceNormal , VLFLfaceNormal

Example Illustration

 missing image of VLnorm(VL)

Syntax

[NL,DL]=VLnorm(VL)

Input Parameter

VL: Vector list

Output Parameter

NL: Normal vector list
DL: Norm length list (Distance)

Examples


VL=[rand(1000000,3);0 0 0];
tic; [x,y]=VLnorm(VL); toc;
tic; [x]=VLnorm(VL); toc;
tic; [~,x]=VLnorm(VL); toc;
tic; z=normr(VL); toc




Copyright 2012-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

Last html export of this page out of FM database by TL: 2025-09-21