Hi all,
how can i determine a series of points are forming a curve? any input is welcomed!
-s
http://en.wikipedia.org/wiki/Interpolation
anyone knows a better/simpler solution. I just want to know if the mouse movement is forming a circle/curve or so. It doesn't need to be accurate.
you can listen for a MouseEvent.MOUSE_MOVE. From this event you can tell the x and y location of the mouse. from there its some simple math. take two of the 3 or more points given and form an equation in the form of y = mx + b. once you find your m and b for the equation, just plug in x for your third point. If the answer is y then it's on the line. otherwise its part of a curve. the mouse event won't fire every millisecond though, so you will only get some of the points of the mouse move depending on how fast the user moves the mouse. To control that, you can raise your lower your frame rate. the faster the frame rate, the more often the mouseEvent will fire. (or so I think, that last part might only be on enterFrame events)
" the faster the frame rate, the more often the mouseEvent will fire."
Mouse move is mouse move and it is hardware related - it has practically nothing to to with Flash player per se. This means that whenever mouseX or mouseY change - it is recorded. Also, mouse position is always an integers.
So, there is no direct dependency on frame rate. Experimental data shows that even with frame rate 1 intervals between recorded mouse moves is almost the same as with 60 fps which makes sense. This interval is typically 8 ms.
"anyone knows a better/simpler solution. I just want to know if the mouse movement is forming a circle/curve or so. It doesn't need to be accurate."
What would be implications if you, say, know user's intentions? How your program will react to establishing this knowledge?
As I said in my previous post - each iteration of mouse move is recorded as integers. This means, in part, that the line between two consequent recorded mouse positions is ALWAY a straight line no matter how small.
I guess it is up to you to define, based on the task you need to implement, what constitutes curve - this is the main challenge I think. I see many different ways to look at it.Say, I scatter 100 randomly positioned points over some plane. What does program have to see - circle encompassing all the points, square, ellipse?
Once curve definition is in place - developing algorithm and math formulas will be more straightforward.
You need at least 3 points for this test, because as Andre said any two points are on a straight line - in fact, any two points are on a circle, or on any kind of curve!
private function areThesePointsOnStraightLine(p1:Point, p2:Point, p3:Point):Boolean {
return p3.y == (p2.y - p1.y)*(p3.x - p1.x)/(p2.x - p1.x) + p1.y;
}
trace(areThesePointsOnStraightLine(new Point(2, 4), new Point(4, 8), new Point(8, 16)));
// true: 3 points are on a straignt line
trace(areThesePointsOnStraightLine(new Point(2, 4), new Point(4, 8), new Point(-10, 3)));
// false: 3 points are not on a straight line
North America
Europe, Middle East and Africa
Asia Pacific