Tutorial: Spatial arrangement of geometric bodies (solid geometry) relative to each other

Prof. Dr. Tim C. Lueth, Professor at Technical University of Munich, MIMED - Department of Mechanical Engineering, Munich July 2025

Development history

While in SGLib the polygons and surface models were initially arranged by translations and rotations using homogeneous transformation matrices, this is still possible with SGtrans0, SGtrans1, SGtransP, SGtransR, SGtransT, etc., the desire arose early on to do this relative to other bodies. Initially, the "bounding box" of bodies (from 2013) played a dominant role, resulting in functions such as SGincenter, SGontop, SGinfront, SGbehind, SGleft, SGright, and SGunder. For kinematic chains, the arrangement relative to "frames" then played a role (SGTset, SGTget, SGtransT) (from 2015). Their complexity The "feature surfaces" (from 2017, first used in 2012 under "union") were introduced as the final concept. In order to be able to apply these different concepts uniformly, the function "SGtransrelSG" was introduced at the end of 2016. Gradually, the functions for spatial application are now being restricted again, and the focus is being placed on SGtransrelSG.

Assignment of spatial relations to coordinate axes

In the SG Library, the standard representation for spatial axes is view(-30,30). In this representation, the larger coordinate values of x and y run away from the observer and smaller numerical values toward the observer. In this representation:
are assigned.
SGfigure; view(-30,30);

Use of two sample bodies (surface models)

We create two bodies by extrusion
SGofCPLz(PLsquare([30,20]),10); A=ans; SGcolorfaces(A,'g');A=ans; title('Solid A');
SGofCPLz(PLstar(13),9); B=ans; SGcolorfaces(B,'r');B=ans; title('Solid B');
 
 
% SGtextstamp2('B',[0 0 1],B)

Simple relative spatial relations

Position one body in the center of the other object
B=SGtransrelSG(B,A,'center'); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('center');
Position one body above the other object
B=SGtransrelSG(B,A,'ontop'); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('ontop');
Position a body to the left of another object
B=SGtransrelSG(B,A,'left'); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('left');
Placing a body in the center of another object, also available separately as "centerx," "centery," "centerz"
B=SGtransrelSG(B,A,'center'); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('center');
Arrange a body at the upper object boundary
B=SGtransrelSG(B,A,'aligntop'); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('aligntop');

Simple relative spatial relations with parameters

Place a body at the left edge of the object and then 2 mm above it.
B=SGtransrelSG(B,A,'aligntop',2); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('aligntop',2);
Arrange a body at the left object boundary
B=SGtransrelSG(B,A,'alignleft'); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('aligntop');
Place a body at the left edge of the object and then move it 10 mm to the right.
B=SGtransrelSG(B,A,'alignleft',-10); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('alignleft',-10);

Simple relative spatial relations, linked and interruptible with "debug" for step-by-step control of translations.

By inserting "debug," you can display the current status and must press the Enter key in the command window of matlab to continue. You can see how body B is first moved, displayed with 'debug', and then moved back to the center.
B=SGtransrelSG(B,A,'alignleft',-10,'debug','center'); SGfigure(-30,30); SGplotalpha(A); SGplotalpha(B); titleprintftext('alignleft',-10,'debug','center');

Rotation, translation along the main coordinate axes, centering only in one axis,

Boolean operations following spatial relations

The functions for Boolean operations are presented separately again, but for convenience they are also integrated into the function "SGtransrelSG." It is often the case that a Boolean operation is prepared with SGtransrelSG, and in practice, only a new line would need to be programmed to add/subtract or cut the bodies. It therefore makes sense to offer this option directly in SGtransrelSG. For this reason, both "1st\2nd" ("minus") and '2nd\1st' ("sub") are offered

"B and A" == "A and B"

With the Boolean "A and B," the order of A and B does not matter.
A=SGofCPLz(PLsquare([30,20]),10); A=SGcolorfaces(A,'g');
B=SGofCPLz(PLstar(13),9); B=SGcolorfaces(B,'r');
B=SGtransrelSG(B,A,'center','alignleft',-10,'add'); SGfigure(-30,30); SGplotalpha(A,'g'); SGplotalpha(B,'r'); titleprintftext('center','alignleft',-10,'add');

"A without B"

In the Boolean "A without B," the order of A and B plays an important role: The function therefore uses the order as parameters '1st\2nd' or '2nd\1st'.
A=SGofCPLz(PLsquare([30,20]),10); A=SGcolorfaces(A,'g');
B=SGofCPLz(PLstar(13),9); B=SGcolorfaces(B,'r');
B=SGtransrelSG(B,A,'center','alignleft',-10,'2nd\1st'); SGfigure(-30,30); SGplotalpha(B,'r'); view(51,14); titleprintftext('center','alignleft',-10,'sub');

"B without A"

With the Boolean "A without B," the order of A and B is important: The function therefore uses the order as parameters '1st\2nd' or '2nd\1st'.
A=SGofCPLz(PLsquare([30,20]),10); A=SGcolorfaces(A,'g');
B=SGofCPLz(PLstar(13),9); B=SGcolorfaces(B,'r');
B=SGtransrelSG(B,A,'center','alignleft',-10,'1st\2nd'); SGfigure(-30,30); SGplotalpha(B,'r'); titleprintftext('center','alignleft',-10,'minus');

"A intersect B" == "B intersect A"

In the Boolean "A intersect B," the order of A and B does not matter.
A=SGofCPLz(PLsquare([30,20]),10); A=SGcolorfaces(A,'g');
B=SGofCPLz(PLstar(13),9); B=SGcolorfaces(B,'r');
B=SGtransrelSG(B,A,'center','alignleft',-10,'intersect'); SGfigure(-30,30); SGplotalpha(B,'r'); titleprintftext('center','alignleft',-10,'intersect');

Further parameters of SGtransrelSG

help SGtransrelSG
SGtransrelSG(SGA,SGB,rel,gap) - changes position of a solid relative to another solid (by Tim Lueth, SG-Lib, 2016-DEZ-07 as class: SPATIAL RELATIONS) The fnctn allows the successive linking of spatial arrangements! This fnctn replaces a set of other fnctns and does support the transformation frames structure There are also: SGincenter, SGunder, SGontop, SGinfront, SGbehind, SGleft, SGright, SGaligntop, SGalignbottom, SGalignfront, SGalignback, SGalignleft, SGalignright This fnctn supports also relative spatial arrangement relative to frames This fnctn allow the supports the relative arrangement to Feature Surfaces ========== Supported relative spatial relations: ==================================== - "under", "ontop", "left", "right", "behind", "infront", all with optional second displacement parameter such as ..,'ontop',3,.. - "alignunder", "aligntop", "alignleft", "alignright", "alignbehind", "aligninfront", all with optional second displacement parameter such as ..,'alignleft',3,.. - "center", "centerx", "centery", "centerz", all with optional second parameter such as ..,'centerx',3,.. ========== Supported frame name operations: ========================================== - "matchT" with following cell {<FNameA>,<FNameB>,<Optional T>} for matching frames of solid a and B - "alignT" with following cell {<FNameA>,<FNameB>,<Optional T>} - for matching frame axis y of solid A and B - "alignTx", "alignTy", "alignTz" with following cell {<FNameA>,<FNameB>,<Optional T>} - for matching frame axis x, y, z of solid A and B ========== Supported individual operations: ========================================= - "transx", "transy", "transz", all with second parameter such as ..,'transz',3,.. - "rotx", "roty", "rotz", all with second angle parameter such as ..,'rotz',pi/2,.. - "magnify" with second parameter of magnification size ========== Supported boolean operations: ============================================ - "cat", - "plus", "minus", "overlap", ========== Supported absolut positioning: =========================================== - rotx, roty, rotz ========== Supported postprocessing: =============================================== - "col, color" - "grow" - "breakv", "radialv" - "cut, cutz" - 'debug' - 'info' ===========ALPHABETIC LIST =========================================================== bottom,under,down,below ontopT ontop,up,top left right infront behind trans,transP,vary,varyof transx transy transz transud translr transfb centerx centery centerz incenter,center alignright alignleft alignbehind,alignback aligninfront,alignfront aligntop alignbottom, alignunder varySG axisalign magnify,mag shrink cut,cutz adjustsx transT removeT,remT matchT alignTy,alignT, alignt alignTx alignTz attached,touch cat plus,add supp,supplement minus,removed sub crossed,overlap,intersect color,col grow breakv radialv rotz rotx roty help,info,? debug (Status of: 2025-07-27) Introduced first in SolidGeometry 3.1 See also: SGTsetorigin, SGtransT, Gtrans0, SGtrans1, SGtransP, SGtransR, SGtransrelT [SG,T]=SGtransrelSG(SGA,SGB,[rel,gap]) === INPUT PARAMETERS === SGA: Transformed Solid Geometry SGB: Final spatial transformation matix rel: spatial relations gap: gap, Optional parameter after an relation command === OUTPUT RESULTS ====== SG: Transformed Vertices and Frames T: Transformation used to transform solid SGA EXAMPLE: Align relative to geometry and relative to frames SGtransrelSG(SGA,SGB,'top','alignright',-5,alignback) SGtransrelSG(B,A,'alignT',{'B','B'}) A=SGbox; SGtransrelSG(A,A,'rotx',pi/2,'minus','?') See also: SGTsetorigin, SGtransT, Gtrans0, SGtrans1, SGtransP, SGtransR, SGtransrelT Copyright 2016-2025 Tim C. Lueth Published output in the Help browser

Call the function "SGtransrelSG" without a second body

There are cases where you want to call up the relations without a second body at short notice. In this case, a very small throw is automatically designed at the coordinate origin.
"ontop" then places the lower edge on the xy plane.
B=SGofCPLz(PLstar(13),9); B=SGcolorfaces(B,'r');
SGtransrelSG(B,'','ontop',20);
 
% "under" then sets the lower object boundary to the xy plane.
SGtransrelSG(B,'','under',-20);
 
% Here too, the commands can be chained together.
SGtransrelSG(B,'','center','rotx',45,'roty',45);
 
% or with radial edges
SGtransrelSG(A,'','center','rotx',45,'roty',45,'radialv',1);
Processing corner Nr 1 = [1.288521e+01 9.507738e+00 -9.673386e+00] Analyze union areas for 4 facets: Major union vectors: 3 found with maximum size of 600. Finally 3 union areas found with size > 1.000000e-12 Processing corner Nr 1 = [-2.874453e+00 9.507738e+00 1.585372e+01] Analyze union areas for 13 facets: Major union vectors: 3 found with maximum size of 1199. Finally 3 union areas found with size > 1.000000e-12 Processing corner Nr 1 = [-1.735519e+01 -9.987023e-01 6.913754e+00] Analyze union areas for 9 facets: Major union vectors: 3 found with maximum size of 1176. Finally 3 union areas found with size > 1.000000e-12 Processing corner Nr 1 = [-1.595530e+00 -9.987023e-01 -1.861335e+01] Analyze union areas for 14 facets: Major union vectors: 3 found with maximum size of 1164. Finally 3 union areas found with size > 1.000000e-12 Processing corner Nr 1 = [1.735519e+01 9.987023e-01 -6.913754e+00] Analyze union areas for 5 facets: Major union vectors: 3 found with maximum size of 600. Finally 3 union areas found with size > 1.000000e-12 Processing corner Nr 1 = [1.595530e+00 9.987023e-01 1.861335e+01] Analyze union areas for 13 facets: Major union vectors: 3 found with maximum size of 1197. Finally 3 union areas found with size > 1.000000e-12 Processing corner Nr 1 = [-1.288521e+01 -9.507738e+00 9.673386e+00] Analyze union areas for 8 facets: Major union vectors: 3 found with maximum size of 1151. Finally 3 union areas found with size > 1.000000e-12 Processing corner Nr 1 = [2.874453e+00 -9.507738e+00 -1.585372e+01] Analyze union areas for 21 facets: Major union vectors: 3 found with maximum size of 1170. Finally 3 union areas found with size > 1.000000e-12
 
% or with broken edges
SGtransrelSG(A,'','center','rotx',45,'roty',45,'breakv',1);
eza = 4×3
0.7240 0.5253 0.4470 0.7240 0.5253 0.4470 -0.4470 0.8509 -0.2760 0.5253 0.0000 -0.8509
eza = 6×3
-0.5253 -0.0000 0.8509 -0.4470 0.8509 -0.2760 -0.5253 0.0000 0.8509 0.7240 0.5253 0.4470 -0.4470 0.8509 -0.2760 -0.4470 0.8509 -0.2760
eza = 5×3
-0.7240 -0.5253 -0.4470 -0.7240 -0.5253 -0.4470 -0.5253 -0.0000 0.8509 -0.4470 0.8509 -0.2760 -0.4470 0.8509 -0.2760
eza = 8×3
0.5253 -0.0000 -0.8509 0.5253 -0.0000 -0.8509 -0.4470 0.8509 -0.2760 -0.7240 -0.5253 -0.4470 -0.4470 0.8509 -0.2760 0.5253 0.0000 -0.8509 -0.4470 0.8509 -0.2760 -0.4470 0.8509 -0.2760
eza = 6×3
0.7240 0.5253 0.4470 0.5253 -0.0000 -0.8509 0.5253 0.0000 -0.8509 0.4470 -0.8509 0.2760 0.7240 0.5253 0.4470 0.5253 0.0000 -0.8509
eza = 8×3
0.4470 -0.8509 0.2760 0.7240 0.5253 0.4470 -0.5253 -0.0000 0.8509 0.7240 0.5253 0.4470 0.4470 -0.8509 0.2760 0.7240 0.5253 0.4470 -0.5253 0.0000 0.8509 0.7240 0.5253 0.4470
eza = 7×3
-0.5253 -0.0000 0.8509 -0.7240 -0.5253 -0.4470 -0.5253 -0.0000 0.8509 0.4470 -0.8509 0.2760 -0.5253 0.0000 0.8509 -0.7240 -0.5253 -0.4470 -0.5253 0.0000 0.8509
eza = 10×3
-0.7240 -0.5253 -0.4470 0.5253 0.0000 -0.8509 -0.7240 -0.5253 -0.4470 0.5253 -0.0000 -0.8509 0.4470 -0.8509 0.2760 0.4470 -0.8509 0.2760 0.4470 -0.8509 0.2760 0.4470 -0.8509 0.2760 -0.7240 -0.5253 -0.4470 -0.7240 -0.5253 -0.4470
etc. However, it should be noted that functions such as rounding edges or breaking edges are not possible with all geometries, and that there are also restrictions with Boolean operations that are related to the triangulation functions in 2D and 3D (currently delaunayTriangulation) and the Boolean functions for 2D surfaces (currently polyshape) as well as the fundamental numerical problems when using homogeneous transformation matrices and the numerical limitation for cross products and angle tables to only 7 significant decimal places in floating point arithmetic (even with 64-bit numerics)
stamp
stamp: Mac OSX 15.6.1 | R2024b Update 6 | SG-Lib 5.4 | Java 1.8.0_202-b08 | i7-Intelx64 6-Core 64GByte RAM | 22-Aug-2025 12:10:33