# Differential elements

`tikzphysics.elements` provides polar and Cartesian differential nodes and
teaching constructions for sphere, cylinder, cone and sheet integrals. The
package loads the library automatically; selective loading also works:

```latex
\usepackage{tikz}
\usetikzlibrary{tikzphysics.elements}
```

All diagram defaults are black and white. Physical nodes, boundaries, hidden
edges and dimension lines inherit the surrounding native TikZ line width.
Dimension arrows use `>=latex`; labels inherit the document or node font.
Colors, widths, patterns and arrow tips remain author-controlled TikZ options.
The module does not require a notation or font package.

## Polar nodes and integer percentages

| Node | Construction |
| --- | --- |
| `polar element` | Annular sector |
| `differential sector` | Sector with zero inner radius |
| `differential ring` | Complete annulus with a 360 degree sweep |
| `spherical shell` | Thin spherical shell shown in section |
| `hollow sphere` | Finite concentric spherical wall shown in section |
| `unwrapped ring` | Differential strip of width `2*pi*r` and height `dr` |

```latex
\begin{tikzpicture}[>=latex]
  \node[polar element,element inner radius=3cm,
    element outer radius=3.2cm,element start angle=-15,
    element delta angle=30] (P) {};
  \fill (P.outer-37) circle (1.5pt);
  \fill (P.centroid) circle (1.5pt);
\end{tikzpicture}
```

Every percentage family accepts each integer from 0 through 100, including
intermediate values such as 37. Coordinates follow rotations and node scaling.

| Node family | Direction |
| --- | --- |
| `inner-T`, `outer-T` | Counterclockwise from start angle to end angle |
| `start-T`, `end-T` | Inner radius to outer radius on the respective radial edge |
| `bottom-T` on strips/rectangles | Left to right |
| `right-T` | Bottom to top |
| `top-T` | Right to left |
| `left-T` | Top to bottom |

A full ring begins its arc families at `element start angle` (default 30
degrees). Set it to zero to start at the rightmost point. The 0 and 100 arc
anchors coincide on a full ring. A sector with zero inner radius collapses its
inner family to the centre. `center` is the circle centre; `centroid` is the
true area centroid and can lie outside a thin annular sector. Full-circle
compass anchors describe the enclosing circle's placement box; use boundary
families when you need the material boundary itself.

The annular-sector centroid lies on the angular bisector at distance
`(2/3) * sinc(delta/2) * R * (1+q+q^2)/(1+q)`, where `q=r/R` and the sinc
argument is in radians. Normalized radii avoid point-valued square overflow.
For sweeps below 0.1 degrees the stable limiting sinc value 1 is used; its
relative error is below 1.3e-7. PGF coordinates otherwise use fixed precision.

| Polar key | Default |
| --- | --- |
| `element inner radius` | `1.8cm` |
| `element outer radius` | `2cm` |
| `element radial thickness` | Derived; setting this derives the outer radius |
| `element start angle` | `30` degrees |
| `element delta angle` | `30` degrees; full-circle presets use `360` |
| `element dimension offset` | `4mm` |

Radii accept TeX dimensions or bare centimetres. The inner radius is
nonnegative, outer radius is greater than the inner radius, and a supplied
radial thickness is positive. Angular width lies in `(0,360]`. Angles are
unitless degree values.

Use `source element=P` on an `unwrapped ring` to copy the named node's radii.
The inner reference radius must be positive. The strip uses the differential
approximation `2*pi*r*dr`; the exact finite-annulus area additionally contains
`pi*dr^2`. It is not an exact finite-area flattening.

## Cartesian nodes

`rectangular element`, `rectangular strip` and `rectangular sheet` share the
four boundary families above and ordinary corner anchors. Text is centred
using the native TikZ node text box. Width and height must be positive.

| Node | Default width | Default height |
| --- | --- | --- |
| `rectangular element` | `8mm` | `6mm` |
| `rectangular strip` | `4cm` | `2mm` |
| `rectangular sheet` | `5cm` | `3cm` |

Set `element width` and `element height` independently. `show dimensions`
draws `dx`, `dy`, or the strip's corresponding labels. Named nodes record
resolved dimensions through `\geometryvalue{A}{width}` and `{height}`.
Polar nodes similarly record inner/outer/mean radii, radial thickness and
start/delta/end angles; unwrapped rings additionally record circumference.

## Named integration constructions

| Pic | Highlight and default expression |
| --- | --- |
| `differential ring diagram` | Ring plus matching strip |
| `sphere shell diagram` | `dV = 4*pi*r^2*dr` |
| `sphere slice diagram` | `dV = pi*y^2*dx` |
| `hollow sphere diagram` | `V = 4*pi*(R^3-a^3)/3` |
| `cylinder shell diagram` | `dV = 2*pi*r*h*dr` |
| `cylinder slice diagram` | `dV = pi*R^2*dz` |
| `cone slice diagram` | `dV = pi*r(x)^2*dx` |
| `sheet element diagram` | `dA = dx*dy` |

```latex
\pic (C) {cylinder slice diagram={
  element body radius=1.6cm,element body height=3.4cm,
  element position=.55,element axial thickness=2mm
}};
\fill (C-slice-top-rim-37) circle (1.5pt);
\draw[->] (C-height-0)--(C-height-100);
```

Pics use hyphenated coordinate names. Their child nodes use normal dot anchors:
`(C-slice.center)`. Existing `body`, `slice`/`shell`, `center` and
`formula-anchor` components remain available. Cone pics also expose `apex`
and `base`; sheet pics expose `body` and `element`; ring pics expose `ring`,
`strip` and body compass coordinates. Dummy body/slice boxes are for placement;
the new rim families locate actual displayed ellipses.

| Pic | Integer coordinate families |
| --- | --- |
| Sphere slice | `disk-rim-T` |
| Cylinder shell | `body-rim-T`, `shell-outer-rim-T`, `shell-inner-rim-T`, `height-T` |
| Cylinder slice | `body-rim-T`, `slice-top-rim-T`, `slice-bottom-rim-T`, `height-T` |
| Cone slice | `body-rim-T`, `slice-top-rim-T`, `slice-bottom-rim-T`, `height-T` |

Rims run counterclockwise from the rightmost point of the projected ellipse,
with 25 at the top, 50 at the left, 75 at the bottom, and 100 returning to the
start. Cylinder `body-rim` is the upper circle; cone `body-rim` is the base.
`height` runs bottom to top along the central axis, measuring physical axial
height rather than the bounding box including ellipse depth. The cylinder
shell's `h` marker uses this same physical height. Cone slice top/bottom rim
radii differ according to the cone slope.

The sphere slice's normalized `element position` is signed `x/R`, strictly
between -1 and 1. Its disk radius is `R*sqrt(1-(x/R)^2)`. Cylinder position
runs bottom to top in `[0,1]`, with the slice centred at that position. Cone
position runs apex to base in `(0,1)`, locating the slice's upper face; its
lower face lies one axial thickness farther toward the base. Finite slices
must fit within the body. Their illustrated differential formula uses a
single local cross-section; exaggerated thickness is a teaching schematic.

`element projection ratio` lies in `(0,1]` and controls apparent ellipse depth,
not physical radius. Horizontal projected circles hide their upper half;
the vertical sphere disk hides its left half and shows its right half.
`element axial thickness`, `element body radius`, `element body width` and
`element body height` must be positive. Sheet placement fractions in `[0,1]`
locate the element within the available interior, keeping it inside the sheet.

Change annotations with `element radius label`, `element radial label`,
`element angular label`, `element arc label`, `element circumference label`,
`element width label`, `element height label`, `element axial label`,
`element body radius label`, `element cavity radius label` and
`element formula label`. An empty formula label suppresses that formula.

Style nodes directly with `draw`, `fill`, `pattern`, `pattern color`, `font`
and `line width`. The shared hooks are `every element dimension`,
`every element label`, `every element body`, `every element center`,
`every solid element`, `every solid hidden edge`, and `every <pic name>`.
Use `/.append style` to add author-selected appearance. Debug/reference
interfaces include `show anchors`, `show keys`, and `\physicshelp`.

Rendered examples: `elements-circular-differentials.tex`,
`elements-solid-geometries.tex`, `elements-fonts.tex` and
`elements-percentage-anchors.tex`. The last gallery covers large-radius
centroids, transformed boundaries, projected rims and native stroke defaults.
