A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Simulating cable physics

  1. #1
    Member
    Join Date
    Jun 2001
    Location
    UK
    Posts
    63

    Simulating cable physics

    Hello,

    I'm working on a project where I would like the user to be able to drag virtual audio cables onto some hardware in a flash application and position each end in a virtual socket.

    The action I'm looking for is close to the cable/pipe physics here yahoo pipes

    Basically 2 moveable ends and a "bendy" cable

    I dont have the first clue about physics in actionscript, is anyone aware of any tutorials along this line ?

    TIA

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    The physics you're asking about is called inverse-kinematics (or IK-chains)...but that is overkill for what you're describing.

    The easy way is best shown in a diagram...see the attached. You're trying to get from point A to point C...what you need to do is calculate points ab and bc and use those as your control-points for two bezier curves. eg:

    PHP Code:
    moveTo(A.xA.y);
    curveTo(ab.xab.yB.xB.y);
    curveTo(bc.xbc.yC.xC.y); 
    Attached Images Attached Images

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You don't actually need physics for that effect. What you do need is an understanding of Bezier curves.

    Bezier curves are a mathematical way of describing a curve with 3 points. The start, end, and a control point. There's another class of curves with four points (start, end, and two control points) which allows a bit more flexibility, but they're a bit harder to work with in flash because they're not built in.

    Conceptually, the control point is the point in space where lines tangent to the curve and going through the endpoints intersect. Read that again, it's a bit confusing.

    Check out wikipedia:
    http://en.wikipedia.org/wiki/B%C3%A9zier_curve

    I couldn't tell in my brief exploration of that site whether their cables use one or two control points. If it's just one, then you can use the built in curveTo method in the Graphics class to draw such curves once you've calculated the 3 points necessary.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center