Skip navigation
seanad1209
Currently Being Moderated

a point of a curve

Jun 6, 2011 5:04 PM

Hi all,

how can i determine a series of points are forming a curve? any input is welcomed!

 

-s

 
Replies
  • Currently Being Moderated
    Jun 6, 2011 5:17 PM   in reply to seanad1209

    If you are talking about curve drawn at authoring time - there is no way to read graphics data.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2011 4:56 PM   in reply to seanad1209

    Not if the line was drawn at authoring on Flash stage.

     

    If the line was drawn at runtime, on the other hand, you can store coordinates and commands in arrays and read these arrays as needed.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2011 8:32 PM   in reply to seanad1209

    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)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2011 5:18 PM   in reply to soccerFootballer


    " 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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2011 5:31 PM   in reply to seanad1209

    "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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2011 8:38 AM   in reply to seanad1209

    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
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2011 10:47 PM   in reply to kennethkawamoto2

    mouse coordinates likely will NOT be on a straight line

    . It might be better to calculate the angle of turn between pts 1, 2 and pts 2,3 to see if it is a clear turn left or right

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 10, 2011 2:44 AM   in reply to birnerseff

    If you use angle further away from the reference point the margin gets wider. You can factor some tolerance into the equation above though.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points