Integral of Sketch

I want to create an animation of motion based on a student’s sketch of a velocity vs. time graph, which would require finding the area under their sketch. Since I can obtain a list of x- and y-values of all points of the sketch, in theory I should be able to do something like a Riemann sum to calculate the area. But without any looping structures in CL, how can I go through and sum up so many tiny contributions to the area?

I just realized I can use the calculator to set up the summation instead of the computation layer. Now, though, I seem to be having a problem with sketch.pointXValues and sketch.pointYValues. Has anyone worked with either of those functions before? I created numberLists for each and sent them to the calculator to plot, but it doesn’t seem to be working.

It looks like it doesn’t do a list of coordinates if a continuous line is drawn. It only works for points. You should try using xValuesAt or yValuesAt instead (although I don’t know if you can use a list for this, so it might be too cumbersome). I’m not sure how it handles no “xValuesAt”, so you might need some kind of conditional to handle that in your area calculation.

If it’s helpful, we’ve recently updated the sample code in the documentation Computation Layer Documentation

Unfortunately, it looks like yValuesAt only accepts a number as an argument, not a numberList.