Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Flash Math

Contributor ,
Aug 23, 2007 Aug 23, 2007
Any good ActionScript mathematicians out there?

I keep getting "NaN" on this value, but should not be.

lambda = (Math.sqrt(((x*2)+(y*2)) - R0) * (1/R1));

where:
x = x coordinate
y = y coordinate
R0 = radius of a circle
R1 = radius of another circle

With this variable, I get a mix of valid numeric values and sometimes "NaN". It appears that the formula is valid, but that some of the values are going beyond what Flash can recognize.

What limitations does ActionScript have with number generation?


TOPICS
ActionScript
375
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 23, 2007 Aug 23, 2007
The only place I see would be a problem is if any of these variables were undefined, or of type text because they were coming from a text field (or XML or some such), or if R1 was equal to zero. You can add this line immediately before lambda.

trace([x,y,R0,R1]);

Paste the response.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 23, 2007 Aug 23, 2007
Most likely, ((x*2)+(y*2)) - R0 < 0. Flash can't square root negative numbers.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 23, 2007 Aug 23, 2007
D'oh! I should have seen that coming. Yeah.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2007 Aug 23, 2007
beyond that being the root of a negative number, when he's getting NaN:

x*2 +y*2 should probably be x*x + y*y.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 24, 2007 Aug 24, 2007
LATEST
interesting, this might explain why a few of my pythagorean calcs don't always work too. So other than tracking the quad, and using Math.abs, how could one go about making this calc on a cartesian system? use other trig, I suppose, or Point.distance prop?

EDIT: strike that 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines