PDA

Click to See Complete Forum and Search --> : Can flash draw a quartic??



Tim H-L
12-17-2002, 06:07 PM
Hello,

I want to be able to draw quartic equations (aX^4 + bX^3 + cX^2 + X + u)with flash.

I work for a climate change think tank and we want rebuild a planning model we have which charts future CO2 emissions scenarios.

The key graphic we are generating, is a stack of 180 bell shaped curves modeled with a quartic equation for each country (an image is attached).

Our current model is a 10MB excell file and I am hoping that with Flash MX it can be much smaller by using vectors.

My initial trawling of the net tells me that the vectors in flash are all binomials.
Do you have any ideas or know of code that could help in this quartic qest??.

Many Thanks,

Tim.

nimmit
12-18-2002, 01:05 PM
What your on about is way over my head but this link (http://www.robertpenner.com/scripts/easing_equations.txt) might help?

brutfood
01-09-2003, 04:36 AM
curveTo() creates a quadratic curve - but this doesn't stop you from building higher order curves or shapes from straight line segments? (It is possible to use quadratic segments - but probably not worth it).

Have I missed the issue? It looks easy?

10MB? For 180 sets of 4 parameters? Wow!

hexagone
01-14-2003, 07:28 AM
Hello,
I would say that flash would be too slow for this application. With any large number of vectors or indeed points the flash player/exe/projector would not cope and jam up i fear.
cheers
Hexagone

Tim H-L
01-17-2003, 11:36 AM
Thank you nimmit, brutfood and hexagone for responding to my post. I have been working to get up to speed understanding FLASH and your comments have been very helpful.

Thanks nimmit for the link to Robert Penner http://gizma.socalleddesign.com/easing/

I am interested in his code for a quartic quartic. I am asuming that this is being drawn with straight lines, as it ignores the curveTo function.
___________________________________________
Math.easeInOutQuart = function (t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t*t*t + b;
t -= 2;
return -c/2 * (t*t*t*t - 2) + b;
};
____________________________________________

The other way of creating a quartic seems to be to aproximate it with a string of curveTo quadratic curves. http://www.timotheegroleau.com/Flash/articles/cubic_bezier/cubic_bezier_in_flash.htm

Hexagone, you pointed out that flash might sieze up if it has to crunch too many vectors. how many do you think is too many? I am wondering if I can side step the problem by performing them sequentialy and build up the image as a little animation.

Do you think I would optimise processing by using flashes internal curveTo function to aproximate the curve or to ignore it and draw them from a fresh quartic equation a bit like Robert Penner?

Cheers,
Tim

Dickee
01-17-2003, 09:52 PM
hey Tim H-L!

I've been exploring this since you first posted, and I've come up with an example to show a possible set of results(although not close to your requested bell curve), with input to try different segment iterations, using 100 'lineTo' instructions per segment. I found very little difference in speed issues between creating a new line mc for every segment and redrawing segments into one line mc (which is just a little faster, so I've used it in the example).

quarticEquation1.2 .swf (http://members.shaw.ca/flashmath101/quarticEquation1.2.swf) .fla (http://members.shaw.ca/flashmath101/quarticEquation1.2.fla)

I'm on a rather slow machine (Athlon 550), but I suspect even faster machines will start to slow down after 80-100 iterations. The 180 segments you're requesting takes 11-12 seconds according to the onstage field, but actually takes about 37 seconds before rendering (at least on my machine), and functionality stalls after rendering that many segments. That doesn't even factor in the weight of your fills needed beneath each segment.

Bottom line: you could probably attempt this with a maximum of 80-100 segments, but 180 won't fly.

I would be interested to see a list of input expression:value pairs that you are using, and to know which expressions in the quartic that you wish to map? I can't seem to be able to render a bell curve, no matter which two expressions I solve for.

Richard

acion84
01-18-2003, 07:08 PM
Dickee.. I ran your movie on my machine, i stopped upping the segments after i got to 260 rendered in 3.617 seconds on my (P4 2.4) and 180 segments rendered in 7.511 seconds on my (P3 750). I just thought you would like to hear how it was acting with a few different setups. Anyhow, good work.

mkantor
01-28-2003, 10:35 AM
Tim,

I believe that the way to draw your bell curves is this: draw ONE bell curve (I export graphs from graphing software as EPS, import into Flash). Then produce each of your 180 bell curves by scaling and shifting this ONE bell curve, using _x, _xscale, _yscale.

In general, you can produce any cubic from the graph of y = x^3 by using manipulations Flash provides. You can't get a general quartic (though you can get close with a combination of rotation and skew), but yours will be symmetric if they are approximating bell curves.

(And if you're approximating a bell curve by a quartic, then you're working in a realm where that kind of precision doesn't matter.)

If you want more details, I'll be happy to provide them. Just ask.

Tim H-L
02-03-2003, 11:25 AM
Hi Dickee,

Thanks for quarticEquation1.2, I have been having a play with it.
I am still very much at the novice stage in all this FLASH. I can start to see how the action script is put together and am now getting to grips with doing it myself.
My current plan is to use a series of curveTo quadratics to aproximate each quartic path. Timothy Groleau has done some good work on this for cubics. I hope I can extend the code to work on quartics.
Somewhere between 4 and 10 quadratics gives a "visibly exact" aproximation of a cubic. I asume similar figures for a quartic. On the other hand I expect that the processing of curveTo is more intensive than lineTo so I don't know if it would be slower overall or not.
See the library file available from:
http://www.timotheegroleau.com/Flash/articles/cubic_bezier/cubic_bezier_in_flash.htm

I am not quite sure what you mean by a "value pair". However here is an example of the kind of quartic I will need to produce.
x values from 0 to 1. y=-23x^4+65x^3-57x^2+11x+7

This is a projected curve of future carbon emissions. It would sit next to (follow on from) a grahph that plotted rising historic emissions.

To Mkantor,
Thank you for your suggetion. Unfortunately the quartic I want to draw is not a simple or symetrical bell shaped curve. I need the flexability that each of the quartics components provide, to design all sorts of possible curves, that are not just scaled versions of each other.

I think my next step is to get to grips with Timothee Groleau's code and then try to expand it to make quartics.

Cheers,
Tim.