00:00
00:00
Newgrounds Background Image Theme

emoloser21 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

ActionScipt lengths?

612 Views | 9 Replies
New Topic Respond to this Topic

ActionScipt lengths? 2006-07-27 18:40:50


In actionscipt can you find out how long a line is... i need it for this pivot kinda thing im making here it is so far.

dawdadahjka link!

Response to ActionScipt lengths? 2006-07-27 18:43:58


At 7/27/06 06:40 PM, stickman_638 wrote: In actionscipt can you find out how long a line is...

Distance Formula!

x1 = first._x;
y1 = first._y;
x2 = second._x;
y2 = second._y;
distance = Math.sqrt(Math.pow((x1-x2), 2)+Math.pow((y1-y2), 2));


Hi there!

BBS Signature

Response to ActionScipt lengths? 2006-07-27 18:53:11


At 7/27/06 06:43 PM, jmtb02 wrote:
At 7/27/06 06:40 PM, stickman_638 wrote: In actionscipt can you find out how long a line is...
Distance Formula!

x1 = first._x;
y1 = first._y;
x2 = second._x;
y2 = second._y;
distance = Math.sqrt(Math.pow((x1-x2), 2)+Math.pow((y1-y2), 2));

Please may you explain the code? I really wanta learn more.

Response to ActionScipt lengths? 2006-07-27 19:04:35


At 7/27/06 06:53 PM, stickman_638 wrote:
distance = Math.sqrt(Math.pow((x1-x2), 2)+Math.pow((y1-y2), 2));
Please may you explain the code? I really wanta learn more.

Lets do some vector maths.

You have two sets of co-ordinates, - pair 1 and pair 2, which become x1, y1 and x2 and y2 respectively. X1, Y1 may be the shoulder blade and Y1 Y2 may be the elbow, for instance, with the line of length L between them.

The formula above works out the length of a line - so...

L = Square Root ( [x1-x2]^2 + [y1-y2]^2 )

So if point 1 is at 1,1 and point 2 is at 4,4...

L = Square Root ( [1-4]^2 + [1-4]^2 )
L = Square Root ( [-3]^2 + [-3]^2 )
L = Square Root ( 9 + 9 )
L = Square Root of 18

Easy...

I'm guessing, however, this is NOT what you are after... you're trying to make a ragdoll or an IK frame as far as I can tell... this tutorial by T-H may help you...

...

BBS Signature

Response to ActionScipt lengths? 2006-07-27 19:06:06


At 7/27/06 07:04 PM, KaynSlamdyke wrote:
I'm guessing, however, this is NOT what you are after... you're trying to make a ragdoll or an IK frame as far as I can tell... this tutorial by T-H may help you...

Sorry... Here's the link for the Ragdoll / Constant Distance Tutorial

Gotta love the fact that links don't show up in quoted text... >.<


...

BBS Signature

Response to ActionScipt lengths? 2006-07-27 19:08:15


At 7/27/06 06:53 PM, stickman_638 wrote:
At 7/27/06 06:43 PM, jmtb02 wrote:
At 7/27/06 06:40 PM, stickman_638 wrote: In actionscipt can you find out how long a line is...
Distance Formula!

x1 = first._x;
y1 = first._y;
x2 = second._x;
y2 = second._y;
distance = Math.sqrt(Math.pow((x1-x2), 2)+Math.pow((y1-y2), 2));
Please may you explain the code? I really wanta learn more.

Given two points in a coordinate plane, we can determine the length of them using the pythagorean theorem (Because really, we know 4 points when we know 2).

So the pythagorean theorem states that a²+b² = c², given that distances a and b are perpendicular to each other and that c is the hypotenuse between them. So if we know where the first point is, we are given an x and y value (hence, the x1 and x2 above). Secondly, we know the second point, which is x2 and y2. From these values, we can determine a lot.

x1 and x2 are a certain distance away. To determine that distance, we just subtract them from each other. So (x1-x2) = a in the pathogorean theorem. Same for y, so y1-y2 = b. So far, we have (x1-x2)² + (y1-y2)² = c².

So to solve for c, we just take the square root of both sides, so...

c = squareroot((x1-x2)²+(y1-y2)²). There you go.

Now for the actionscript, its very simple. By defining your x's and y's up front, you dont have to keep on typing point._x or something._y. And here is some of the script.

Math.sqrt() will give you the square root of the value inside the ().

Math.pow(number, power) will give you number raised to the nth power, which is your second parameter.

I hope that helps, I hated geometry.


Hi there!

BBS Signature

Response to ActionScipt lengths? 2006-07-27 19:09:22


Its meant to be like a stoped motion of a stick scene or something like that the problem is that the lines stretch, i want the to stay the same size the whole time.

Response to ActionScipt lengths? 2006-07-27 19:13:10


At 7/27/06 07:09 PM, stickman_638 wrote: Its meant to be like a stoped motion of a stick scene or something like that the problem is that the lines stretch, i want the to stay the same size the whole time.

As I said. The constant distance tutorial by T-H should help out tonnes for your Kinematic needs...


...

BBS Signature

Response to ActionScipt lengths? 2006-07-27 19:16:14


Link?

Response to ActionScipt lengths? 2006-07-27 19:18:22


At 7/27/06 07:16 PM, stickman_638 wrote: Link?

I posted it up in the thread.
But here it is again..


...

BBS Signature