viewvec() - Get Cartesian Normal Vector of Current Axis View
Version 1.0.0 (2.35 KB) by
John Kearns
viewvec() returns the cartesian normal vector of the current axis view. Developed as the inbuilt view() mainly returns spherical angles.
viewvec(AxHandle) returns the cartesian normal vector for the current view/camera position of AxHandle.
normVec = viewvec(AxHandle);
% Inputs: AxHandle; Handle of the target axis object.
% Uses current axis (as in gca) is no input is specified
% Outputs: normVec; % a 1x3 normal vector of current view in target axis.
This function extends the utility of MATLAB's inbuilt 'view()' function, which only returns the shperical angles (or viewing matrix) of the current camera view. While 'view()' accepts a vector as an input to define the camera position/viewing angle, it cannot output a cartesian vector of the current view.
I wrote this because, when making figures for my research, I found that plotting curves over triangulation objects (such as when highlighting the free boundary of an STL/triangulation object with a coloured plot output) can lead the edges of the triangulation to bleed into the curve. While this can often be rectified by plotting two axes over one another, that is not always feasible to do and multiple overlaid axes increases the complexity of a script. The normal vector output from 'viewvec()' facilitates easy adjustment of axis children such that they are in front of or behind other other children relative to the current view, but will appear to be in the same position relative to the current view as they were prior to adjustment.
An example is included that shows points on a surface that appear to be unmoved relative to the initial camera position.
Cite As
John Kearns (2024). viewvec() - Get Cartesian Normal Vector of Current Axis View (https://www.mathworks.com/matlabcentral/fileexchange/132203-viewvec-get-cartesian-normal-vector-of-current-axis-view), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2023a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
viewvec
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |