Michael Penn just discussed an interesting calculus problem on his channel. Please check the YouTube link for complete analysis. My post is about using a quite general method to handle this type of problem using affine transformation base on built-in linear transformation in WL.
There are two benefits
There are two benefits
◼
XXXTransform-like function can be used like function head component. Easily apply to not only point but also polygon and other graphics objects with GeometricTransformation. It is convenient to create animation in this way.
◼
Describe motions in terms of affine transform and vector algebra helps understanding the fundamental dynamics and tensor base transformation, typically the right sequence to application of translation and rotation. This is a key concept in courses like rigid body dynamics.
Motion of the boxes
Motion of the boxes
The base shape of both boxes are unit square centered at origin = {0,0}
RegularPolygon
2
2,4According the document, the first argument indicates the radius of the circumscribed circle is . This is required to have the side length of the inscribed square to be one. The second argument explains itself: a square has 4 sides.
2
2WL provides the simple rotation transformation if I need to rotate a point wrt {0,0} clockwise for θ angle.
In[]:=
RotationTransform[-θ][{x,y}]
Out[]=
{xCos[θ]+ySin[θ],yCos[θ]-xSin[θ]}
It also provides a second argument in RotationTransform to specify {a,b} as the center of rotation in a 2D plane
In[]:=
RotationTransform[-θ,{a,b}][{x,y}]
Out[]=
{a-aCos[θ]+xCos[θ]-bSin[θ]+ySin[θ],b-bCos[θ]+yCos[θ]+aSin[θ]-xSin[θ]}
I can use both as the first operation and then do translation. But which one is better? In the first case, the rotation does not change the coordinate of the center of the square. But the ending point (new center for the tilted square) is unknown
The second method is better in our case. If we choose the center of the rotation to be {-1/2,-1/2}, I can handle the translation in the next step easily by calculating the difference between two vectors {0,Sin[θ]} - {-1/2,-1/2} = {0,Sin[θ]} + {1/2,1/2}
Thus my affine transformation is taken the following form. Notice it is import to do rotation FIRST and translation follows.
In[]:=
affine[θ_]=Composition[TranslationTransform[{0,Sin[θ]}+{1/2,1/2}],RotationTransform[-θ,-{1/2,1/2}]]
Out[]=
TransformationFunction
Cos[θ] | Sin[θ] | 1 2 |
-Sin[θ] | Cos[θ] | 1 2 |
0 | 0 | 1 |
For any θ between 0 and π/2, I can transfer base square to the red box by
GeometricTransformationRegularPolygon
2
2,4,affine[θ]I can immediately find the coordinate of point 4 by
In[]:=
affine[θ][{-1/2,1/2}]
Out[]=
-++(Cos[θ]+Sin[θ]),++(Cos[θ]+Sin[θ])
Cos[θ]
2
Sin[θ]
2
1
2
Cos[θ]
2
Sin[θ]
2
1
2
For the black square, the only operation is the translation along {-1/2, -1/2} -> point 5 in the diagram above. The x coordinate of point 5 is the same as that of point 3, which is computed by
In[]:=
{affine[θ][{1/2,1/2}]〚1〛,0}
Out[]=
++(Cos[θ]+Sin[θ]),0
Cos[θ]
2
Sin[θ]
2
1
2
because point 3 is from {1/2,1/2} under my affine transform. point 7 is just point 5 translating along {1,1}
In[]:=
{affine[θ][{1/2,1/2}]〚1〛,0}+{1,1}
Out[]=
1+++(Cos[θ]+Sin[θ]),1
Cos[θ]
2
Sin[θ]
2
1
2
Find Y
Find Y
Just recall the line intersection function I use frequently for community blogs. It returns
◼
the fraction of lengths between endpoints and intersections
◼
exact coordinate of the intersection as the last element in the result
In[]:=
segmentIntersection[p1_List,p2_List,p3_List,p4_List]:=Block[{u,v},Module[{sol},sol=Solve[u*(p2-p1)+p1v*(p4-p3)+p3,{u,v}];{u,v,u*(p2-p1)+p1}/.sol〚1〛]]
The y I am looking for is the intersection of y axis (a line thru {0,0} and {0,1} )and the line connecting point 4 and point 7
In[]:=
segmentIntersection[{0,0},{0,1},affine[θ][{-1/2,1/2}],{affine[θ][{1/2,1/2}][[1]],0}+{1,1}]//FullSimplify
Out[]=
1+,-Tan,0,1+
Sin[2θ]
1+Cos[θ]
θ
2
Sin[2θ]
1+Cos[θ]
Nice! I have a clean expression form for y
In[]:=
yIntersection[θ_]:=1+
Sin[2θ]
1+Cos[θ]
Find the maximum
In[]:=
FullSimplify@Maximize[{yIntersection[θ],θ≥0,θ≤π/2},θ]
Out[]=
1+
-22+10
,θ2ArcTan5
-2+
5
Here is the answer to the problem. This is same result from Michael’s instruction
In[]:=
Framed[%[[1]]]
Out[]=
I can also visualize the location of the maximum between [0, π/2]
Roughly explain why not π/4
Roughly explain why not π/4
Of course when θ = π/4, point 4 is at the highest position. But to have large value of y, point 7 is better be close to point 4 (for instance thinking about connecting point 4 to point 8, instead of to point 7). It is clear that point 7 is slight closer to point 4 after θ passes π/4 than at π/4.
Animation
Animation
Just wrap up everything we have so far into Manipulate.