PDA

Click to See Complete Forum and Search --> : Friends of ED book on math



darrentheturkey
04-19-2002, 06:00 PM
Has anyone bought the Friends of ED book Flash and Math(i forgot the exact title). I saw it today in a bookstore and it looked interesting. Any opinions?

koganinja
04-22-2002, 05:16 PM
i heard it's really good. not only do you learn the examples in the book but you also get the knoledge for using this stuff in your own project. it's the next book i'm buying. if you want to know how it is email me and when i get it i tell you. peace

koganinja
04-22-2002, 05:18 PM
the book has it's own site,
http://www.friendsofed.com/fmc/index.html

darrentheturkey
04-22-2002, 06:42 PM
I went ahead and bought it. It is good. I have enjoyed playing around with it so far.

bit-101
04-23-2002, 09:12 AM
i thought it was pretty cool too. but then again, i'm biased :D

danjames
04-23-2002, 07:28 PM
I bought it, because I need more maths for my flash and I wasn't awake enough at school. Its great - at the moment I'm working my way through David Hirmes work and I've learnt loads. I make his examples and then start changing them - today I was trying to work out a way to get a 1 to a 100 value from a Math.sin(i*(Math.PI/180)) starting point, went round the houses, phoned friends, then discovered two examples down the line that he's done it already, and it was right there in the book!! (but my way worked too - his is just more elegant!

The best of my flash books.

Gloomycus
05-11-2002, 03:54 PM
I'd buy it but the American to Canadian conversions are too high - it would cost me well over $70.

Gloomycus
05-11-2002, 03:56 PM
By the way Bit, your methods of creating elasticity, gravity are far too complex. There are easier methods.

tublu
05-11-2002, 04:32 PM
they also have some good examples / FLAs on the site ... some of they are pretty amazing as well !!

bit-101
05-11-2002, 04:59 PM
Originally posted by Gloomycus
By the way Bit, your methods of creating elasticity, gravity are far too complex. There are easier methods.


please share.

ironmallet
05-12-2002, 08:38 PM
distSQ = dx*dx+dy*dy;
force = grav*b[j].m*b[k].m/distSQ;
total = Math.abs(dy)+Math.abs(dx)
ddx = (force*dx)/total;
ddy = (force*dy)/total;


Bit, my gravity routine is based on yours, so the variables might look familiar. I avoided trig by just splitting the total force proportionately between the x and y axis. It's correct, but I don't know that it is better, since Math.abs isn't necessarily quicker than trig, but it is different. I'm curious about the much less complex method for elasticity and gravity that Gloomycus has. :)

bit-101
05-15-2002, 03:28 PM
i'm still waiting.

"my" method for gravity:

gravity=1;
vy+=gravity;
mc._y+=vy;

i honestly want to see something less complex than that. :)

elasticity/spring:

k=.2;
dx=targetx-mc._x;
dy=targety-mc._y;
ax=dx*k;
ay=dy*k;
vx+=ax;
vy+=ay;
mc._x+=vx;
mc._y+=vy;

i don't see how you could get a spring with less than that. of course you could COMBINE several of the steps and get something like:

mc._x+=vx+=((targetx-mc._x)*.2);
mc._y+=vy+=((targety-mc._y)*.2);

but that's the same thing in shorthand.

bit-101
05-15-2002, 03:43 PM
ironmallet, i did a test with your method and it does not give the same values as using trig. it's about .74 what the actual values would be. maybe close enough for flash though :)

ironmallet
05-16-2002, 04:49 AM
be warned-- this post is 100% bunk, I thought it made some sense at the time, read it if you slow down to look at car wrecks

It's different by a constant, so it's proportionally correct. You just have to change the 'gravitational constant', G.
I'll call the trig G, 'G2'
my supposition is that G=k*G2, where k is always the same

two examples:
ball 1 mass = 50kg, position=1m,3m (over and down)
ball 2 mass = 100kg,position=3m,4m

METHOD 1 (similar triangles)
so dist=sqrt(5), so distsq=5

force = G*(50*100)/5 = G*1000

total = 3

forcex = force*dx/total = g*1000*2/3 = 666G
forcey = force*dx/total = g*1000*1/3 = 333G

METHOD 2 (trig)
dist = sqrt(5), so distsq=5

force = G2*(50*100)/5 = G2*1000

angle (in radians) = atan(-1/2) = -.4636
c=cos(angle)= .8944
s=sin(angle)= .4472

forcex=c*force=G2*1000*.8944=894.4*G2
forcey=s*force=G2*1000*.4472=447.2*G2

so it appears that G=.75*G2, so k=.75

For the next i'll use 100 for both of the masses, and eliminate the units.
position ball 1 (67,89)
position ball 2 (115,-30)
dx=48, dy=-119
METHOD 1
so distsq=16465
force=G*10000/16465
total=167
forcex=(48/167)*(G*10000/16465)=.174*G
forcey=(119/167)*(G*10000/16465)=.432*G

METHOD 2
distsq=16465
force=G2*10000/16465
angle=atan(-119/48)=-1.1874
c=cos(angle)=.374
s=sin(angle)=.927
forcex=(.374)*(G2*10000/16465)=.227*G2
forcey=(.927)*(G2*10000/16465)=.563*G2

this time I got .77 for k, but that's rounding error.

anyway the point is that as long as the two forces change by the same factor, and that factor is the same for all angles, and is unaffected by distance, it's just a matter of tweaking the gravitational constant
[Edited by ironmallet on 05-19-2002 at 12:11 AM]

ironmallet
05-16-2002, 05:43 AM
you know what, i can't think of any hard reasons why my way should work.

my method is basically claiming that

cos(atan(a/b))=k*(a/(a+b))

which just isn't so

weird, it makes sense-sortof

ironmallet
05-16-2002, 12:24 PM
okay, sorry for blowing up this thread and all, but I figured out for sure that my method does not work!

In this example, the stationary particle figures out the forces using trig, the mouse following particle figures out the forces using the similar triangles method (which I still need to think through why it doesn't work). G is calculated and you can watch it change from .708 (sin 45) to up to 1. Not exactly a constant :)

http://www.ironmallet.com/flashkit/gravitydemo.html

Thanks for calling my attention to this bit, actually the first time I used this method was in 11th grade in C, on an apple ][. I've never noticed the error before, it's subtle.

ahab
05-18-2002, 04:23 PM
Originally posted by ironmallet
distSQ = dx*dx+dy*dy;
force = grav*b[j].m*b[k].m/distSQ;
total = Math.abs(dy)+Math.abs(dx)
ddx = (force*dx)/total;
ddy = (force*dy)/total;

This code is very wrong. The variable "total" makes no sense. If you want your code to work "total" should hold the distance between the two objects.


distance_squared = delta_x * delta_x + delta_y * delta_y;
distance = Math.sqrt (distance_squared);

force_gravity = G * mass1 * mass2 / distance_squared;

force_x = force_gravity * delta_x / distance;
force_y = force_gravity * delta_y / distance;

In the calculation of "force_x" and "force_y" you calculate the sine and cosine of the angle between the objects by dividing "delta_x" and "delta_y" by "distance." No need for a trigonometric function.

ironmallet
05-18-2002, 11:59 PM
Uh, yeah.

yes, thank you.

That's the way to avoid the trig function. The main problem with the 'total' ly wrong way I was doing it is, it looked like it worked... thanks bit and ahab.

It's so painfully obvious now that in a 3 4 5 triangle

3/5 not 3/7 of the force goes one way
4/5 not 4/7 of the force goes the other

criminey

ahab, btw, your site is sweet-- the 'batting demo' is sick.
[Edited by ironmallet on 05-19-2002 at 12:06 AM]

Ed Mack
06-01-2002, 06:23 PM
I think

mc._y += (vy++);

Is a lot simpler than:

gravity=1;
vy+=gravity;
mc._y+=vy;

So there!

bit-101
06-01-2002, 11:13 PM
as i said in the same post, you can combine several steps, but that doesn't make the formula simpler, merely makes the code less understandable and less maintainable. so there! :)

Ed Mack
06-02-2002, 06:17 AM
More complex? As if. I saved the usage of another variable, and its a simple line. How about we have a vote?

bit-101
06-02-2002, 09:07 AM
i didn't say "more complex"
i stand by my last post.

Ed Mack
06-04-2002, 07:27 AM
Ok, "less understandable" hehe

I just don't see how it is less understandable? This way, you don't have to remember what 3 different variables are for.

bit-101
06-04-2002, 07:41 AM
additional variables, if well named, make code more understandable, not less. vy++ just says you are incrementing a variable vy. velocityY+=gravity says it all. short, compact code isn't necessarily better. it can sometimes be more efficient, but hell to maintain. i'm being a bit of a hypocrite here, since my personal source code is often pretty messy and breaks all kinds of rules for "proper programming style". but when i'm doing a tutorial or book, or code that someone else will need to use, i try to be a little more PC (programatically correct) :)

Ed Mack
06-04-2002, 12:06 PM
But they clutter everything up whilst in the debug process and make life harder sometimes.

pog21
06-04-2002, 05:28 PM
It seems to me that keeping a gravity variable can only make the code more flexible: While authoring it enables one to change the gravitational force for many parts of a system quickly and easily. Isn't this the point of not hard coding everything?
You may want to include a slider to control gravity at run time.
Overall I think it's simpler and more flexible.

bit-101
06-04-2002, 07:26 PM
damn variables! should just get rid of 'em once and for all!
:)

Quantuvis
06-09-2002, 07:24 AM
Would the book be interesting for someone with a great knowledge of math as well? Or is it merely as an inspiration and "help" for those who have forgotten a lot of math since school?

Ed Mack
06-09-2002, 07:35 AM
I suppose a proper math book would be more for sombody in that position, ie. one that's going over more advanced topics, but not flash.