I have a parametric plot showing a path of an object in x and y (position), where each is a function of t (time), on which I would like to put a time tick, every second let's say. This would be to indicate where the object is moving fast (widely spaced ticks) or slow (closely spaced ticks). Each tick would just be short line that crosses the plot at that point in time, where that short line is normal to the plotted curve at that location.
I'm sure I can figure out a way to do it using lots of calculations and graphics primitives, but I'm wondering if there is something built-in that I have missed in the documentation that would make this easier.
(Note: this is about ticks on the plotted curve itself -- this doesn't have anything to do with the ticks on the axes or frame.)
Answer
To create the ticks perpendicular to the curve, I calculate the direction of the normal to the curve where the ticks are to be placed and then orient a line segment along that direction. The following code does that.
ClearAll[ParametricTimePlot]
SetAttributes[ParametricTimePlot, HoldAll]
ParametricTimePlot[fun_, {var_, min_, max_, steps_}, len_,
opts : OptionsPattern[]] :=
Show[
ParametricPlot[fun, {var, min, max}, opts],
Graphics[
Rotate[Translate[Line[{{-len/2, 0}, {len/2, 0}}], #1], ArcTan @@ #2]
] & @@@ (N@Table[{fun, RotationMatrix[π/2].D[fun, var]} /. var -> i,
{i, min + steps, max, steps}])
]
Use the above function as:
ParametricTimePlot[{ Sqrt[t] Cos[t], Sqrt[t] Sin[t]}, {t, 0, 2 π,
π/10}, 0.1, PlotStyle -> Blue]
If you want to keep it simple and just show the dots, then this is very straightforward:
ClearAll[ParametricTimePlot]
SetAttributes[ParametricTimePlot, HoldAll]
ParametricTimePlot[fun_, {var_, min_, max_, steps_}, opts : OptionsPattern[]] :=
ParametricPlot[fun, {var, min, max}, opts]
~Show~
ListPlot[Table[fun /. var -> i, {i, min, max, steps}],
PlotStyle -> Red, PlotMarkers -> {Automatic, 8}]
ParametricTimePlot[{ Sqrt[t] Cos[t], Sqrt[t] Sin[t]}, {t, 0, 2 Pi, Pi/10},
PlotStyle -> Blue]
Comments
Post a Comment