title: Most efficient way to find min and max of a sin/cos curve in C#
body: <p><b>Background:</b> I have a function in my program that takes a set of points and finds the minimum and maximum on the curve generated by those points. The thing is it is incredibly slow as it uses a while loop to figure out the min/max based on approximated error. Not completely sure what formal method this is because I did not write it myself, but I know we need a new and more efficient one.</p>
  
  <p><b>Question:</b> My question is what is the best and most efficient method/algorithm to finding the min max points on a curve, using C#, that is also very accurate?</p>
  
  <p><b>About the curve:</b> I have my Numerical Analysis book from college near me, so all I need is a method name and a nudge in the right direction. I can generate as many points as I choose to approximate the curve, but I want to keep the number of points to an efficient minimum. The curve is always in the shape of one segment of a Sin/Cos curve, but not always the same curve and will always be less that one period. The range of Theta is 0&deg; to 359.999...&deg; It has some phase and amplitude shift and Y will never be negative. This function/algorithm will have to run fast as it will be run every several hundred milliseconds as the curve changes.</p>
  
  <p>Any suggestions are appreciated.</p>
  
  <p><b>EDIT</p>
  
  <p>More info on the curve:</b> The points are generated on mouse move. The points are a set of points based on the length of a rubber belt in a drive design with an idler, such as one like the serpentine belt in a car. The position of the idler determines the length of the belt and I get the curve [belt length(y) vs idler position(x)]. The idler in this case is a pivoting idler and will have constant circular motion. If the drive design changes the curve will change, either because the length points change, or because the range of motion of the idler has been constrained. The range of motion in the idler is potentially 0&deg; to 359.999...&deg; and is theta as stated above. For a slotted idler the maximum range is 1/2 of the period of the curve (easier problem).</p>
  
  <p>I guess what I need is a general solver for both types of idlers, but the real issue is with the pivoting idler.</p>