7
$\begingroup$

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:

enter image description here

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.

$\endgroup$
7
  • $\begingroup$ You can actually do this: df[{x_, y_}] = RegionDistance[axis, {x, y}] ( the integral is not returning now, but that's a different issue ) $\endgroup$
    – george2079
    Sep 2, 2016 at 20:25
  • $\begingroup$ @george2079: Perhaps I'm missing something, but with your definition of df I get an error message about how "only assignments to symbols are allowed". $\endgroup$
    – Pirx
    Sep 2, 2016 at 20:36
  • $\begingroup$ Did you mean to write InfiniteLine[{{-1, yc}, {1, yc}}] (with an extra {})? This gives a line through the two points specified. $\endgroup$
    – mikado
    Sep 2, 2016 at 20:41
  • $\begingroup$ @Mikado: Ah, yes, you're right. Fixed my post, but the change makes no difference in the outcome. $\endgroup$
    – Pirx
    Sep 2, 2016 at 20:44
  • 1
    $\begingroup$ Wait...I failed to notice my df gives a patently wrong result for the distance (!) $\endgroup$
    – george2079
    Sep 2, 2016 at 21:01

2 Answers 2

8
$\begingroup$

You can reasonably expand the definition of RegionDistance to cover this case:

Unprotect[RegionDistance];
RegionDistance[InfiniteLine[{u_List, v_List}]] := Function[{x},
  Module[{p, d},
   p = Normalize[u - v];
   d = x - u;
   Norm[d - (p.d) p]]]
Protect[RegionDistance];

This then allows you to evaluate the expressions you gave without problem

inertialMoment[reg_?RegionQ, axis_InfiniteLine] := 
 Module[{df = RegionDistance[axis]}, 
  Integrate[df[{x, y}], {x, y} ∈ reg]]

yc = RegionCentroid[Disk[{0, 0}, r, {0, Pi}]][[2]]
axis = InfiniteLine[{{-1, yc}, {1, yc}}];
(* (4 r)/(3 π) *)

And it now works with symbolic r

Assuming[r > 0, inertialMoment[Disk[{0, 0}, r, {0, Pi}], axis]]
(* (4 (8 Sqrt[-16 + 9 π^2] r^3 + 
   9 π^2 Sqrt[-16 + 9 π^2] r^3 - 
   54 π^2 r^3 ArcSec[(3 π)/4]))/(81 π^3) *)
$\endgroup$
1
  • $\begingroup$ Awesome, thanks! $\endgroup$
    – Pirx
    Sep 2, 2016 at 20:52
1
$\begingroup$

In 2016, the function MomentOfInertia[] has been introduced.

$\endgroup$
2
  • $\begingroup$ Yep, as I had mentioned in my 2016 post, along with the fact that this was not the point of my question. $\endgroup$
    – Pirx
    Feb 3 at 14:31
  • $\begingroup$ Point taken. Anyway, I found this question looking for this functionality, so the hint may be useful for others. $\endgroup$ Feb 4 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.