Let's say I want to calculate the moment of inertia of a half circle around its centroid. I set up a function to calculate the inertial moment like so:
inertialMoment[reg_?RegionQ, axis_InfiniteLine] :=
Module[{df = RegionDistance[axis]},
Integrate[df[{x, y}], {x, y} \[Element] reg]]
and then define my geometry as follows:
yc = RegionCentroid[Disk[{0, 0}, r, {0, Pi}]][[2]]
axis = InfiniteLine[{{-1, yc}, {1, yc}}];
So now I do
inertialMoment[Disk[{0, 0}, r, {0, Pi}], axis]
and I get:
Now, I think I understand what the message says, and my function works fine if I use a fixed axis, such as
axis = InfiniteLine[{-1, 0}, {1, 0}];
but it doesn't make much sense to have this restriction to an explicitly defined location for this axis. Is there a way around this?
P.S.: I know I can get moments of inertia using the MomenOfInertia
function; the above is just an example.
df[{x_, y_}] = RegionDistance[axis, {x, y}]
( the integral is not returning now, but that's a different issue ) $\endgroup$df
I get an error message about how "only assignments to symbols are allowed". $\endgroup$InfiniteLine[{{-1, yc}, {1, yc}}]
(with an extra{}
)? This gives a line through the two points specified. $\endgroup$df
gives a patently wrong result for the distance (!) $\endgroup$