calculate_moment_of_inertia
Calculate moment of inertia for various shapes using mass, dimensions, and rotation axis.
Instructions
Calculate moment of inertia for various shapes.
Moment of inertia (I) is the rotational equivalent of mass. It determines
how difficult it is to change an object's rotation. Depends on both mass
distribution and rotation axis.
Args:
shape: Shape type - "sphere", "solid_sphere", "hollow_sphere", "rod", "disk", "cylinder", "box"
mass: Mass in kilograms
radius: Radius for sphere/disk/cylinder (meters)
length: Length for rod (meters)
width: Width for box (meters)
height: Height for box/cylinder (meters)
depth: Depth for box (meters)
axis: Rotation axis - "center", "end" (for rod), "x", "y", "z" (for box)
Returns:
Dict containing:
- moment_of_inertia: I in kg⋅m²
- shape: Shape type
- axis: Rotation axis
Common formulas:
- Solid sphere (center): I = (2/5)mr²
- Hollow sphere (center): I = (2/3)mr²
- Rod (center): I = (1/12)mL²
- Rod (end): I = (1/3)mL²
- Disk (center): I = (1/2)mr²
Example - Spinning wheel:
result = await calculate_moment_of_inertia(
shape="disk",
mass=5.0, # 5kg wheel
radius=0.3 # 30cm radius
)
# I = 0.225 kg⋅m²Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| shape | Yes | ||
| mass | Yes | ||
| radius | No | ||
| length | No | ||
| width | No | ||
| height | No | ||
| depth | No | ||
| axis | No | center |
Implementation Reference
- Core implementation: calculates moment of inertia for various shapes (solid sphere, hollow sphere, rod, disk, cylinder, box) using standard physics formulas. Delegated to by the MCP tool endpoint.
def calculate_moment_of_inertia(request: MomentOfInertiaRequest) -> MomentOfInertiaResponse: """Calculate moment of inertia for various shapes. Formulas: - Solid sphere (center): I = (2/5) * m * r² - Hollow sphere (center): I = (2/3) * m * r² - Rod (center): I = (1/12) * m * L² - Rod (end): I = (1/3) * m * L² - Disk (center): I = (1/2) * m * r² - Cylinder (center): I = (1/2) * m * r² - Box (about center, axis through x): I = (1/12) * m * (h² + d²) Args: request: Moment of inertia request Returns: Moment of inertia value """ m = request.mass shape = request.shape axis = request.axis if shape in ["sphere", "solid_sphere"]: if request.radius is None: raise ValueError("radius required for sphere") r = request.radius inertia = (2.0 / 5.0) * m * r * r elif shape == "hollow_sphere": if request.radius is None: raise ValueError("radius required for hollow sphere") r = request.radius inertia = (2.0 / 3.0) * m * r * r elif shape == "rod": if request.length is None: raise ValueError("length required for rod") L = request.length if axis == "end": inertia = (1.0 / 3.0) * m * L * L else: # center inertia = (1.0 / 12.0) * m * L * L elif shape in ["disk", "cylinder"]: if request.radius is None: raise ValueError("radius required for disk/cylinder") r = request.radius inertia = (1.0 / 2.0) * m * r * r elif shape == "box": if request.width is None or request.height is None or request.depth is None: raise ValueError("width, height, depth required for box") w, h, d = request.width, request.height, request.depth # Rotation about different axes if axis == "x": inertia = (1.0 / 12.0) * m * (h * h + d * d) elif axis == "y": inertia = (1.0 / 12.0) * m * (w * w + d * d) elif axis == "z": inertia = (1.0 / 12.0) * m * (w * w + h * h) else: # default to z-axis inertia = (1.0 / 12.0) * m * (w * w + h * h) else: raise ValueError(f"Unknown shape: {shape}") return MomentOfInertiaResponse(moment_of_inertia=inertia, shape=shape, axis=axis) - Pydantic model for the moment of inertia request, validating shape (Literal type), mass, radius, length, width, height, depth, and axis.
class MomentOfInertiaRequest(BaseModel): """Request for moment of inertia calculation.""" shape: Literal["sphere", "solid_sphere", "hollow_sphere", "rod", "disk", "cylinder", "box"] mass: float = Field(..., description="Mass in kg", gt=0.0) # Dimensions depend on shape radius: float | None = Field(None, description="Radius for sphere/disk/cylinder (meters)") length: float | None = Field(None, description="Length for rod (meters)") width: float | None = Field(None, description="Width for box (meters)") height: float | None = Field(None, description="Height for box/cylinder (meters)") depth: float | None = Field(None, description="Depth for box (meters)") axis: str = Field( default="center", description="Rotation axis: 'center', 'end' (for rod), 'x', 'y', 'z' (for box)", ) - Pydantic model for the moment of inertia response, returning moment_of_inertia, shape, and axis.
class MomentOfInertiaResponse(BaseModel): """Response for moment of inertia calculation.""" moment_of_inertia: float = Field(..., description="Moment of inertia in kg⋅m²") shape: str = Field(..., description="Shape type") axis: str = Field(..., description="Rotation axis") - MCP tool endpoint decorated with @tool. Accepts shape, mass, radius, length, width, height, depth, axis as parameters and delegates to the core handler in ../rotational.py.
@tool # type: ignore[arg-type] async def calculate_moment_of_inertia( shape: str, mass: float, radius: Optional[float] = None, length: Optional[float] = None, width: Optional[float] = None, height: Optional[float] = None, depth: Optional[float] = None, axis: str = "center", ) -> dict: """Calculate moment of inertia for various shapes. Moment of inertia (I) is the rotational equivalent of mass. It determines how difficult it is to change an object's rotation. Depends on both mass distribution and rotation axis. Args: shape: Shape type - "sphere", "solid_sphere", "hollow_sphere", "rod", "disk", "cylinder", "box" mass: Mass in kilograms radius: Radius for sphere/disk/cylinder (meters) length: Length for rod (meters) width: Width for box (meters) height: Height for box/cylinder (meters) depth: Depth for box (meters) axis: Rotation axis - "center", "end" (for rod), "x", "y", "z" (for box) Returns: Dict containing: - moment_of_inertia: I in kg⋅m² - shape: Shape type - axis: Rotation axis Common formulas: - Solid sphere (center): I = (2/5)mr² - Hollow sphere (center): I = (2/3)mr² - Rod (center): I = (1/12)mL² - Rod (end): I = (1/3)mL² - Disk (center): I = (1/2)mr² Example - Spinning wheel: result = await calculate_moment_of_inertia( shape="disk", mass=5.0, # 5kg wheel radius=0.3 # 30cm radius ) # I = 0.225 kg⋅m² """ from ..rotational import MomentOfInertiaRequest, calculate_moment_of_inertia as calc_moi request = MomentOfInertiaRequest( shape=shape, # type: ignore mass=mass, radius=radius, length=length, width=width, height=height, depth=depth, axis=axis, ) response = calc_moi(request) return response.model_dump() - src/chuk_mcp_physics/server.py:38-50 (registration)Import of the 'rotational' tools module in server.py, which triggers registration of the @tool-decorated calculate_moment_of_inertia function.
# Import all tools modules to register their @tool decorated functions from .tools import ( basic, rotational, oscillations, circular_motion, collisions, conservation, fluid as fluid_tools, kinematics_tools, statics, convert_units as unit_conversion_tools, )