0

again.

So, what i'm trying to achieve here is that I calculate a random number between 0 - 360 and than convert it to degrees. My teacher told me that i had to use a point.polar.

I've been looking at this the whole day and am now completely lost at what to do.

var minRadial:int = 0;
var maxRadial:int = 360;
var degree = randomRadial (minRadial, maxRadial);

function randomRadial (minRadial:Number, maxRadial:Number):Number 
{
    return (Math.floor(Math.random() * (maxRadial - minRadial)) + minRadial)
}

function randomDegree (degree:Number):Number
{
    return degree * 180 / Math.PI;
}
golyo
  • 517
  • 3
  • 12
Eleonara
  • 35
  • 4
  • my first bet would be that you are trying to get a RADIAL between 0 and 360...which would work but im guessing you are actually trying to get one between `0` and `Math.PI * 2` – golyo Jun 12 '14 at 16:54
  • also using `degree` both as a global and as a local variable might cause namespace errors...same goes for `minRadial` , `maxRadial` – golyo Jun 12 '14 at 16:59
  • I'm sorry, I'm an AS noobie, so i really don't understand. The edits don't help. Still get this error: 1180: Call to a possibly undefined method randomRadial. – Eleonara Jun 12 '14 at 17:35
  • 1
    If i understand you correctly, you want a number between 0 and 360 and convert it to degrees. I believe you mean between 0 and 2 * PI, since 360 radians in degrees is about ~18000 degrees. – golyo Jun 12 '14 at 17:46
  • Also you should not use `Point.polar` here, since you have no `Point` to begin with...code runs fine, and will suffice (even though it's technically wrong) – golyo Jun 12 '14 at 17:52
  • I think you may have misunderstood what your teacher wants you to do. It might be a good idea recheck your assumptions. – J. Holmes Jun 12 '14 at 18:32
  • @MartonPallagi This still doens't fix my error, i'm sorry, really a noob here! – Eleonara Jun 12 '14 at 19:17
  • that's alright, where is you code? do you use flash cs? try an empty fla with this code on the first frame, should work – golyo Jun 12 '14 at 19:45

1 Answers1

0

if you have a Point A and you want to get an other point in a certain angle and a certain distance from A you can use the polar method of the Point object http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Point.html#polar()

it takes 2 arguments, the distance and the angle, the latter in radian http://en.wikipedia.org/wiki/Radian

full circle in degrees is 360, the same in radian are 2 * PI

180° = PI

so you mixed up your variables maxRadial should be maxDegree

// returns a number between 0 and 360 degrees in Radian
function getRandomRad():Number
{
    return Math.PI * 2 * Math.random();
}
prizma
  • 57
  • 3