1
$\begingroup$

I'm experimenting with integrating over regions so I can check some physics simulations. Here's the rundown of what I'm attempting to do.

I have a rectangle that I'm rotating with a parameter:

m = 5;
g = 9.8;
l = 1;
h = 2;
θ0 = π/8;
Shape = Rectangle[{0, 0}, {l, h}];
RotShape[θ_] := Rotate[Shape, θ, {0, 0}];

Essentially, RotShape[θ] is a rectangle rotated around the origin by $\theta$. I'm then integrating over this region performing an angular momentum calculation:

α[θ_] := Integrate[m*g*x, {x, y} ∈ RotShape[θ]]/
   Integrate[m*EuclideanDistance[{0, 0}, {x, y}], {x, y} ∈ RotShape[0]];
s = NDSolve[{(θ'')[t] == -α[θ[t]], θ[0] == θ0, 
   Derivative[1][θ][0] == 0}, θ, {t, 0, 20}]

This has worked exactly as I expected. Here, I've been able to solve for the angular displacement of a rectangle rotating around the origin under gravity.

However, next I tried to alter my region. Rather than rotating freely, if the angle $\theta$ becomes negative I want the axis to switch to the other corner (to simulate the rectangle tipping back and forth).

BounceShape[θ_] := 
 If[θ > 0, Rotate[Shape, θ, {0, 0}], 
  Rotate[Shape, θ, {l, 0}]];
Manipulate[
 Graphics[BounceShape[θ], Axes -> True, 
  PlotRange -> 4], {θ, -π/2, π/2}]

The region looks exactly like I expect it to. I can even integrate over this region for fixed $\theta$. But NDSolve isn't liking it. No matter what I've tried, I can't get it to simulate this.

Any thoughts?

$\endgroup$
5
  • $\begingroup$ Mathematica 12.2 doesn't evaluate your second code block $\endgroup$ Dec 24, 2023 at 8:10
  • 1
    $\begingroup$ Your NDSolve command has wrong syntax. $\endgroup$ Dec 24, 2023 at 8:45
  • 3
    $\begingroup$ @AelMinor Rotate isn't the correct command for your issue. Look for RotationTransform to rotate your region! $\endgroup$ Dec 24, 2023 at 9:01
  • $\begingroup$ When we replace Integrate to NIntegrate, we cann't calculate α[3] $\endgroup$
    – cvgmt
    Dec 26, 2023 at 1:37
  • $\begingroup$ Although RegionQ[Rotate[Rectangle[{0, 0}, {l, 2}], 3, {0, 0}]] == True, but NIntegrate[1, {x, y} \[Element] Rotate[Rectangle[{0, 0}, {l, 2}], 3, {0, 0}]] does not work. $\endgroup$
    – cvgmt
    Dec 26, 2023 at 1:47

1 Answer 1

1
$\begingroup$
  • Although RegionQ[Rotate[Rectangle[{0, 0}, {l, 2}], 3, {0, 0}]] == True but Rotate still not the right way to represent a proper region.
  • Here we use TransformedRegion and RotationTransform.
  • But the NDSolve still get som warning message,but I don't know how to rewrite it.
Clear["Global`*"];
m = 5;
g = 9.8;
l = 1;
h = 2;
θ0 = π/8;
Shape = Rectangle[{0, 0}, {l, h}];
bounceShape[θ_] := 
  If[θ > 0, 
   TransformedRegion[Shape, RotationTransform[θ, {0, 0}]], 
   TransformedRegion[Shape, RotationTransform[θ, {1, 0}]]];
Manipulate[
  Graphics[bounceShape[θ], Axes -> True, 
   PlotRange -> 4], {θ, -(π/2), π/2}];
α[θ_] := 
 Integrate[m*g*x, {x, y} ∈ bounceShape[θ]]/
  Integrate[
   m*EuclideanDistance[{0, 0}, {x, y}], {x, y} ∈ 
    bounceShape[0]]
Plot[α[θ], {θ, -(π/2), π/2}]

enter image description here

s = NDSolve[{θ''[t] == -α[θ[t]], θ[
     0] == θ0, Derivative[1][θ][0] == 0}, θ, {t, 
   0, 20}]

Plot[θ[t] /. s[[1]] // Evaluate, {t, 0, 20}]

enter image description here

$\endgroup$

Your Answer

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

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