figurerotate
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Visualization
Introduced first in SolidGeometry 4.3, Creation date: 2018-09-24, Last change: 2025-09-14
rotates the current figure to show 3D effects
Description
by slowly rotation surfaces, even 2D surface are seen as 3D surfaces
See Also: , viewsmooth
, Videoquickrotate3D
, animatego
, drawnowvid
Example Illustration
Syntax
figurerotate([mtime,angle])
Input Parameter
mtime: | | minimal rotation time; default is 1 |
angle: | | rotation angle; default is 5 degree |
Examples
SGfigure(SGbox(3)); % Show a simple box
figurerotate(5) % rotate for 5 seconds
Copyright 2018-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 is designed to rotate a figure in MATLAB to create a 3D effect, even for 2D surfaces. It is part of the SolidGeometry library and was introduced in version 4.3. The function is called figurerotate and it takes two optional input parameters: mtime and angle.
Input Parameters
- mtime: This is the minimal rotation time in seconds. The default value is 1 second if not specified.
- angle: This is the rotation angle in degrees. The default value is 5 degrees if not specified.
Algorithm Steps
- Initialize
mtime to 0.1 seconds and angle to 5 degrees. If the user provides these values, they are updated accordingly.
- Disable the 3D rotation mode using
rotate3d off.
- Set a flag
breaktrue to false to control the loop execution.
- Bring the current figure to the front using
shg and get the current figure handle hf.
- Set a key press callback function
KBCallback to allow interruption of the rotation.
- Retrieve the current view angles
a and b.
- Start a timer using
tic and enter a loop that runs until the elapsed time is less than mtime and breaktrue is false.
- Within the loop, iterate over a range of angles from -à to à in steps of 0.03 radians.
- For each angle
w, update the view using view(a+1+angle*cos(w), b+angle*sin(w)) to create a smooth rotation effect.
- Use
drawnowvid to update the figure and pause(0.05) to control the speed of rotation.
- If
breaktrue becomes true, exit the loop.
- After the loop, reset the view to the original angles
(a, b).
- Remove the key press callback function.
- Re-enable the 3D rotation mode using
rotate3d on.
Callback Function
The KBCallback function is a simple window callback that sets breaktrue to true when a key is pressed, allowing the user to interrupt the rotation.
Algorithm explaination created using ChatGPT on 2025-08-19 08:11. (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