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

 missing image of figurerotate (mtime,angle)

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

Algorithm Steps

  1. Initialize mtime to 0.1 seconds and angle to 5 degrees. If the user provides these values, they are updated accordingly.
  2. Disable the 3D rotation mode using rotate3d off.
  3. Set a flag breaktrue to false to control the loop execution.
  4. Bring the current figure to the front using shg and get the current figure handle hf.
  5. Set a key press callback function KBCallback to allow interruption of the rotation.
  6. Retrieve the current view angles a and b.
  7. Start a timer using tic and enter a loop that runs until the elapsed time is less than mtime and breaktrue is false.
  8. Within the loop, iterate over a range of angles from -À to À in steps of 0.03 radians.
  9. For each angle w, update the view using view(a+1+angle*cos(w), b+angle*sin(w)) to create a smooth rotation effect.
  10. Use drawnowvid to update the figure and pause(0.05) to control the speed of rotation.
  11. If breaktrue becomes true, exit the loop.
  12. After the loop, reset the view to the original angles (a, b).
  13. Remove the key press callback function.
  14. 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