
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?

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


I went ahead and bought it. It is good. I have enjoyed playing around with it so far.

i thought it was pretty cool too. but then again, i'm biased

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.

general rule bender
I'd buy it but the American to Canadian conversions are too high  it would cost me well over $70.

general rule bender
By the way Bit, your methods of creating elasticity, gravity are far too complex. There are easier methods.

Owner of the ™ thread
they also have some good examples / FLAs on the site ... some of they are pretty amazing as well !!

Originally posted by Gloomycus
By the way Bit, your methods of creating elasticity, gravity are far too complex. There are easier methods.
please share.

Senior Member
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.

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=targetxmc._x;
dy=targetymc._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+=((targetxmc._x)*.2);
mc._y+=vy+=((targetymc._y)*.2);
but that's the same thing in shorthand.

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

Senior Member
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 05192002 at 12:11 AM]

Senior Member
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 sensesortof

Senior Member
success at proving failure!
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.

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.
Code:
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.

Senior Member
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 05192002 at 12:06 AM]

Gross Pecululatarian
I was just reading down this and saw Bit's post
I think
mc._y += (vy++);
Is a lot simpler than:
gravity=1;
vy+=gravity;
mc._y+=vy;
So there!

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!
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
