5

I created a path:

path[x_] := TriangleWave[x*3]
radius[alpha_] := path[alpha/(2 Pi)];

BaseRadius = 3;
vecPC = {{(BaseRadius - radius[alpha])*
     Cos[alpha]}, {(BaseRadius - radius[alpha])*
     Sin[alpha]}}; (*vector*)

ParametricPlot[Flatten[vecPC], {alpha, 0, 2*Pi}, PlotStyle -> Blue, 
 ImageSize -> Medium, PlotRange -> 4]

enter image description here

Now I want to calulate the normal vector of the path at each point. How can you do it ?

As a plus: How can I display some normal vectors along the path ?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
james
  • 3,043
  • 13
  • 29

1 Answers1

9

After simplifying your code quite a bit:

With[{BaseRadius = 3, h = 0.4, n = 45},
     pos[t_] := (BaseRadius - TriangleWave[3 t/(2 π)]) {Cos[t], Sin[t]};
     nrm[t_] = Normalize[Cross[pos'[t]]];
     ParametricPlot[pos[t], {t, 0, 2 π}, 
                    Epilog -> {Directive[Red, Arrowheads[Small]], 
                               Table[Arrow[{pos[t], pos[t] - h nrm[t]}],
                                     {t, 0, 2 π, 2 π/(n - 1)}]},
                    PlotRange -> 4, PlotStyle -> Blue]]

curve and normals

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • Thank you very much for this beautiful and very readable answer !! May I bother you for another question ? How can I take the cross product of the normal (calculated here) and another vector ? I already tried Cross[nrm[t_],vect2] but it does not work. This path should be used as a cam drive, and therefore the torque on the camshaft should be computed. – james Oct 24 '17 at 14:59
  • How do you define the cross product of a two-vector? – J. M.'s missing motivation Oct 24 '17 at 15:00
  • Hmm ...it is still not working. I tried this: radiusVec[t_] = {Cos[t], Sin[t]}; Cross[nrm[t], radius[t]]. I define the cross product as cross(a,b) = |a||b|cos(phi), where phi is the angle between a and b. I though Mathematica would do it automatically ? – james Oct 24 '17 at 15:03
  • That's the dot product... unfortunately Cross[] is not compatible with 2-vectors (except in the use case I gave for generating a normal vector). That's why I was asking for the definition that you use, since you can just implement that manually. – J. M.'s missing motivation Oct 24 '17 at 15:12
  • ah ..yes, you are right. I accidently wrote cos() instead of sin(phi). Thank you very much!! – james Oct 24 '17 at 15:16
  • 1
    @totyped you do know that cam mechanisms are supposed to be continuous to the first derivative to avoid problems. – joojaa Oct 24 '17 at 20:40
  • @joojaa Yes, I do. This path was just for testing purpose. There is still a lot to optimize... – james Oct 24 '17 at 20:46