Syntax
SG=SGcenter(SG,[cstr])
Input Parameter
SG : | | Solid Geometry |
cstr : | | center string such as 'xyz' |
Output Parameter
Examples
SGbox; A=ans; SGtrans1(A); B=ans;
SGcenter(B,'x')
SGcenter(B,'xz')
SGcenter(SGoftext('test'),'xyz')
Copyright 2019-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, SGcenter, is designed to center a solid geometry (SG) along specified axes (x, y, z) based on a given center string (cstr).
Input Parameters
- SG: The solid geometry object that needs to be centered.
- cstr: A string indicating the axes along which the solid should be centered. Possible values include 'x', 'y', 'z', or any combination thereof, such as 'xyz'.
Output
- SG: The centered solid geometry.
- P: A vector indicating the translation applied to center the solid.
Algorithm Steps
- Retrieve the center string (cstr) from the input parameters, defaulting to 'xyz' if not provided.
- Calculate the bounding box (bb) of the solid geometry using the function BBofSG(SG).
- Determine the size of the bounding box (ss) using sofBB(bb).
- Initialize a translation vector P as [0 0 0].
- Iterate over each character in the center string (cstr):
- Case 'x': Calculate the translation vector pp for the x-axis as [-bb(1)-ss(1)/2, 0, 0]. Apply this translation to SG using SGtransP(SG, pp) and update P.
- Case 'y': Calculate the translation vector pp for the y-axis as [0, -bb(3)-ss(2)/2, 0]. Apply this translation to SG using SGtransP(SG, pp) and update P.
- Case 'z': Calculate the translation vector pp for the z-axis as [0, 0, -bb(5)-ss(3)/2]. Apply this translation to SG using SGtransP(SG, pp) and update P.
- Otherwise: If the character is not 'x', 'y', or 'z', issue a warning that the letter is ignored.
- If no output arguments are specified, plot the centered solid using SGfigure and SGplotalpha(SG) with a view angle of (-30, 30).
Algorithm explaination created using ChatGPT on 2025-08-19 00:24. (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