--- jupytext: text_representation: extension: .md format_name: myst format_version: 0.13 jupytext_version: 1.13.7 kernelspec: display_name: Python 3 (ipykernel) language: python name: python3 --- (examples-complex-forms)= # Complex forms The [**superposition principle**](https://en.wikipedia.org/wiki/Superposition_principle) states that the net response caused by two or more stimuli is the sum of the responses caused by each stimulus individually. This principle holds in Magneto statics when there is no material response, and simply means that the total field created by multiple magnets is the sum of the individual fields. It is critical to understand that the superposition principle holds for the magnetization itself. When two magnets overlap geometrically, the magnetization in the overlap region is given by the vector sum of the two individual magnetizations. (examples-union-operation)= ## Union operation Based on the superposition principle we can build complex forms by aligning simple base shapes (no overlap), similar to a geometric union. This is demonstrated in the following example, where a hollow cylinder magnet is constructed from cuboids. The field is then compare to the exact solution implemented through `CylinderSegment`. ```{code-cell} ipython3 import numpy as np import matplotlib.pyplot as plt import magpylib as magpy from magpylib.magnet import Cuboid, CylinderSegment fig = plt.figure(figsize=(14,5)) ax1 = fig.add_subplot(131, projection='3d', elev=24) ax2 = fig.add_subplot(132, projection='3d', elev=24) ax3 = fig.add_subplot(133) sensor = magpy.Sensor(position=np.linspace((-4,0,3), (4,0,3), 50)) # ring with cuboid shapes ts = np.linspace(-3, 3, 31) grid = [(x,y,0) for x in ts for y in ts] coll = magpy.Collection() for pos in grid: r = np.sqrt(pos[0]**2 + pos[1]**2) if 2