将用户生成的折线图与程序随机生成的折线图进行比较

发布于 2024-09-14 00:05:30 字数 212 浏览 15 评论 0原文

该程序将向学生显示折线图。学生必须使用箭头键将角色远离或靠近运动检测器来重新创建该线图,从而创建距离-时间图。我可以捕获程序在绘制图形时生成的数据点。我还可以捕获学生生成的数据点。如何比较这两个图表,同时允许学生有一定的容忍度?我是否应该在绘制图表时或记录所有数据点后尝试检测不正确的图表?虽然有些图表是线性的并且易于比较,但其他图表将是分段函数,具有随机间隔的正斜率、负斜率和零斜率。

谢谢!

The program will show the student a line graph. The student will have to recreate that line graph by moving a character away from or toward a motion detector using the arrow keys, creating a distance-time plot. I can capture the data points that the program generates when drawing its graph. I can also capture the data points gnerated by the student. How can I compare the two graphs while allowing for some tolerance on the student's part? Should I try to detect incorrect graphs as they are being drawn or after all data points are recorded? While some of the graphs will be linear and easy to compare others will be piecewise functions with positive, negative, and zero slopes at random intervals.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望笑 2024-09-21 00:05:30

绘制图表线的顺序重要吗?

您可以将具有特定阈值的点记录到数组/向量中并进行比较。

一种快速而肮脏的方法是使用 2 个二进制(单色,只是黑白)图像:

  1. 一个图像将是“打印屏幕”(BitmapData.draw()) 的图形(例如黑底白字)
  2. 另一个图像将为白色(空白)用于写入黑色像素的 BitmapData
    用户/学生绘图的地方(按下鼠标时)。

例如

userBitmapData.setPixel(mouseX,mouseY,0x000000);

,当绘图完成时(释放鼠标或您设置的任何规则),
您运行一个函数来检查源(原始图)图像中有多少黑色像素
在目标(用户图)图像中匹配。

您可以创建一个包含在差异模式下混合的其他两个位图的 BitmapData,因此任何非黑色的内容都不匹配,或者只需循环遍历所有像素一次并手动检查像素是否匹配。请注意,这依赖于两个图像的尺寸(宽度,高度)相同的事实。

下面是一些代码来说明这一点:

function compare(source:BitmapData,destination:BitmapData,threshold:Number):Boolean{
    var commonPixels:Number = 0, totalPixels:Number = 0;

    for(var j:int = 0 ; j < source.height ; j++){
        for(var i:int = 0 ; i < source.width; i++){
            pixels++;
            if(source.getPixel(i,j) == destination.getPixel(i,j)) commonPixels++;
        }
    }
    trace('matching: ' + (commonPixels/pixels * 100) + ' % ');//delete this line,just testing
    if(commonPixels/pixels >= threshold) return true;
    else                     return false;  
}

//usage:
trace('is the graph correct ?: ' + compare(graphBitmapData,userBitmapData,0.7));

向量/数组版本将是类似的,但不会有视觉提示。根据您的设置,您可能想要测试哪一个最适合您:BitmapData 比数组占用更多内存,但您可以轻松创建位图,将其添加到显示列表并检查看起来是否正确等。

如果速度是一个重要因素,问题:

  • 使用向量。而不是 Array 反向循环可能会更快
  • (最大数为 0,递减)也应该加快速度
  • 你可能会用一个循环而不是两个循环
    例如

    var Pixels:int = source.width * source.height;
    for(pixels;pixels >=0;pixels--)

HTH

Does the order in which the graph lines are drawn matter ?

You could record the points with a certain threshold into an Array/Vector and compare.

A quick'n'dirty way would be using 2 binary(monochrome, just black and white) images:

  1. One image will be a 'print screen'(BitmapData.draw()) of the graph(e.g. black on white)
  2. The other image will be a white(blank) BitmapData that you'll use to write black pixels
    where the user/student draws(has the mouse while it's pressed).

e.g.

userBitmapData.setPixel(mouseX,mouseY,0x000000);

When the drawing is complete(either the mouse is released or whatever rule you set),
you run a function that checks how much black pixels from the source(original graph) image
are matched in the destination(user graph) image.

Either you create a BitmapData containing the other two bitmaps blended on Difference mode, so anything that isn't black is not a match, or just loop through all the pixels once and manually check if the pixels match. Note that this relies on the fact that dimensions(width,height) of the two images are the same.

Here's a bit of code to illustrate this:

function compare(source:BitmapData,destination:BitmapData,threshold:Number):Boolean{
    var commonPixels:Number = 0, totalPixels:Number = 0;

    for(var j:int = 0 ; j < source.height ; j++){
        for(var i:int = 0 ; i < source.width; i++){
            pixels++;
            if(source.getPixel(i,j) == destination.getPixel(i,j)) commonPixels++;
        }
    }
    trace('matching: ' + (commonPixels/pixels * 100) + ' % ');//delete this line,just testing
    if(commonPixels/pixels >= threshold) return true;
    else                     return false;  
}

//usage:
trace('is the graph correct ?: ' + compare(graphBitmapData,userBitmapData,0.7));

The Vector/Array version would be similar, but there would be no visual cues. Depending on your setup, you might want to test which would work best for you: BitmapData takes more memory than Arrays, but you can easily create a Bitmap, add it to the display list and check if looks right, etc.

If speed is an issue:

  • using Vector. instead of Array might be faster
  • looping in reverse(highest number to 0, decrementing) also should speed up things a bit
  • you probably get away with one loop instead of two
    e.g.

    var pixels:int = source.width * source.height;
    for(pixels; pixels >=0; pixels--)

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文