flash actionscript:
+ - The Problem - + I need to create a line that has a set length, between two points. One point will stay fixed while the other I would like to move using actionscript or attach to a movieclip. If the two points are not the maximum distance apart the line would droop because of gravity. Kind of like tug-o-war the line doesn?t stretch when pulled, but is still flexible. I have found some line tutorials out there but they all have to do with elasticity or drag and drop points where im dealing with a movable point (non-drag and drop) and gravity. I have no idea where to start anyone have and thought or good tutorials? Thanks, + - redLetter - +
Is there anyone out there that can help or konw where elce I should ask for help?
+ - First Off - + Thank you for replying to my post, I have been working on this for a long time but im no math wiz some im glad to see there is some hope out there. + - Here?s The Lowdown - + Ok, This information might help you along your way. The purpose of why I would need such a line to exist. I create industrial training animations on how machinery works. I take the schematic drawing for a piece of equipment and bring it to life so the mechanics can better understand problem areas and way to fix them. + - This Requires Some Imagination - + Here is an example. Picture a backhoe. You have an operator?s cab (obviously where the machine is operated from lol) and a boom with a bucket. If you have ever seen a backhoe at work, you have seen the hydraulic lines running down the outside of the boom. In animating such and object this is where the flexi-lines would come into play. + - About Exactness - + The exact curve is not as important, as the length of the line. The length of a hose will never change unless you have a major problem. The point of the cure is to illustrate a realistic movement. All movements in my animations are approximate. I real puorpose of making this work is so the trainees can focus on the movement and not that the line is staying straight, it seems to cause a visual imbalance. + - In Closing - + Thank you all for your help this far, and I hope you can understand my gibberish. Im looking forward to seeing what you can come up with. Happy Actionscripting! + - redLetter - +
ok, that's far easier and will require no math. i'm not that great with control points, so it'll take me a minutes to work-out a reasonable solution. p.s. is the arm/bucket to the rigth or left of the cab?
ok, if your boom arm/bucket is to the left of the cab and has registration point on its right side and a default position of horizontal, you can use, the following to draw a reasonable curve from the base of the arm to the tip of the boom: _root.createEmptyMovieClip("hLine", 1); boomL = boom._width; boomMP = (2*boom._x-boomL)/2; h = 200; /* this is the distance below the horizontal boom that your line droops. */ a = 10; /* this is a factor in the equations but who's doesn't seem to make much diffence */ inc = 3; // increment in boom's rotation btn1.onPress = function() { // i tested with a button press if (boom._rotation<90-inc) { boom._rotation += inc; endX = boom._x-boomL*Math.cos(dtr(boom._rotation)); endY = boom._y-boomL*Math.sin(dtr(boom._rotation)); controlX = boom._rotation*(boom._x-boomMP)/90+boomMP; controlY = boom._y+h-a/90+a/((90-boom._rotation)/20); with (hLine) { clear(); lineStyle(1, 0xff0000, 100); moveTo(boom._x, boom._y); curveTo(controlX, controlY, endX, endY); } } }; function dtr(arg) { return Math.PI*arg/180; }
Interesting assignment and I gave it some thought. I arrived at the conclusion that I don't possess the required logic or mathematical ability to formulate the relationship between the end of the string and the bottom of the curve created by the slack of the line. However, I could tell you how much slack was in the string at each point... and I think armed with that, someone out here with the ability of say KGLAD, could assist further. Basically the line is a set length, so if the distance between the end of the line and the start of the line is less than the total line length then we have a slack line and have to curve the line to a point equal to the slack. so saying that (and we will keep this simple), you have a line that starts at (0,0) and moves through a point at (10,0) to then end of the string at (20,0). The maximum length of the line is 20. okay so we move the line's end point so that it is now at a point (14,-3). From this co-ordinate triangulating from the start point we can obtain the distance between the start and end point using pythagoras' theorem. This effectively gives us the straight distance between the two points, hence the left over from the original maximum length of 20 is the amount of slack on the string. That is where I had difficulty. Formulating a reliable mathematical equation to plot the curvature point from which the line would pass on it's path from the start and endpoints. Hopefully someone else can keep you moving in the right direction soon... I will keep trying other ideas. cheers,
the curve defined by your line is a vertical parabola and will have an equation defined by: f(x) = a*(x - h)**2 + k; where a, h and k are parameters that determine all vertical parabolas. your parabola will go through your two fixed points x1,y1 and x2, y2 and will have a given length = len. this will give us 3 equations in the three unknowns a, h, k. so, we can solve for a,h and k and determine the equation for your parabola. first though, you have to face an unpleasantry: the length of a parabola's segment is not an easy equation with which to deal. your problem is solvable, but unless you can make some simplifications it's going to get ugly fast. can you assume the y1 =y2? ie, the fixed points have the same height? if so, then we can deduce that h=(x1+x2)/2. how accurate does this line have to be? can we approximate the curve or do we have to find the exact curve with the given length?
Don't see what you're looking for? Try a search.
|