ActionScript 2.0 :: Math With Prototypes And Functions - Find The Distance Between Two Points
May 19, 2003
So, right now when I want to find the distance between two points, I go: dist = Math.sqrt((this_x-that_x)*(this_x-that_x)+(this_y-that_y)*(this_y-that_y)) BLECH! I don't want to do that every time. So I want to make a nice little function that I can apply to an object. Problem is, I don't know how to do this. Is it possible to end up with something as easy as: Math.dist(thisclipname, thatclipname)? How do you guys set up functions that do bulky math and return nice clean numbers?
often seen in simple flash games. So you can look at an example. http:[url]....Green object shots a bullet and what i want to acheive is to run bullet toward black bar even if bullet is shot to the left side of the screen. Bullet should make a circle, slow down and change direction to the bar and finally proceed faster and faster to the bar. Simply it should behave like remote control rocket chasing enemy. Right now i am with this: Code: Select all
function movingBull(e:Event):void [code].........
//of course i dont know what should be inside if statement
This code calculates the distance between 2 points by using distance formula, Math.sqrt ( (x1 - x2)^2 + (y1 - y2) ^2). My first point has mmx and mmy coordination and second one has ox and oy coordination. My question is simple, is there any FASTER way for calculate this?
find a points in a line Actually i want to make some footsteps in a sand. The footsteps are dhynamically placed on the stage. How to find the points in a dioganal. see the image
i'm trouble to find a points in a line Actually i want to make some footsteps in a sand. The footsteps are dhynamically placed on the stage. How to find the points in a dioganal.
I'm needing this for a current project, so I have been digging around quite a bit (with little luck) on finding the distance between two points VERY fast. Yes, it is quite critical that it be as optimized as possible. I have the basics, Pythagorean Theorem run in different ways, as well as the Point.distance() function.
I am trying to make a program where I put in a bitmap map and then am able to calculate the distance between two points, and I have done that. Now I want to be able to zoom out and still have those two distance calculate the same distance apart, is there a way to do this with AS3 without have to manually scale my code?
For example I don't necessarily want to have to do var distance = Math.sqrt(dx*dx+dy*dy)/scale... Reason being is I would have to redo a lot of code.
I need algorithm ideas for generating points in 2D space with defined minimum and maximum possible distances between points.
Bassicaly, i want to find a good way to insert a point in a 2D space filled with points, in such manner that the point has random location, but is also more than MINIMUM_DISTANCE_NUM and less than MAXIMUM_DISTANCE_NUM away from nearest points.
I am rotating an object with TweenLite, however instead of a set duration I want the duration to be based upon the distance of rotation where 180 degrees = 3 seconds 90 = 1.5 and so on. Here is my attempt to find the distance of rotation:
var time:Number = Math.abs(Math.atan2(Math.sin(angle-wheelObj.rotation),Math.cos(angle-wheelObj.rotation)); TweenLite.to(wheelObj, time, {shortRotation:{rotation:angle}, ease:Expo.easeOut, onComplete:rotateWheel, onCompleteParams:[target]}); TweenLite.to(carObj, time, {shortRotation:{rotation:angle}, ease:Expo.easeOut});
This just isn't working, time is sometimes huge when the rotation is small and sometimes tiny when it is big, so does anyone know a better way to do this?
I have a LineChar, with one LineSeries, on which i am drawing values ( Y axis ), on specific time ( X axis ).The problem is that i don't wanna the points which is distanced on a specific distance in time ( let say 6 hours ) to be connected.Is there a way to make LineSeries with DateTimeAxis not connecting points distanted in specific time ?
I have a series of variables created that store the distances between two points. I need to find the shortest distance between the two points so I'm storing the results in an array, then sorting the array to show me the smallest number which is the shortest distance. But the problem I have is that I don't need the number I need the variable in the calculation that relates to that number. Make any sense? So if the equation (herexPos - column3Begin) produces the smallest number I need to be able to reference column3Begin after I've sorted the array.
How could I find the distance between a given point and a drawn line? I was thinking about using the point-slope formula to draw a perpendicular line between the point and the line and measuring it as the distance, but I'm not quite sure how to do this in as3.
How does Flash use Math.sqrt to get the distance between 2 movieclips? In the example the only givens are 2 points along a triangle:
function getDistance(x1:Number,y1:Number,x2:Number,y2:Numbe r):Number { var dx:Number=x1-x2; var dy:Number=y1-y2; return Math.sqrt(dx*dx+dy*dy); }
dx is the difference between the x coordinates of 2 points/2 mc's dy is the difference between the y coordinates of the same 2 points the Math.sqrt is the Pythagorean theorum
If the Pythagorean theorum is a^2+b^2=c^2 for the sides of a triangle how do 2 points achieve the same result if the lengths of the sides aren't given?
I created a movie where I have a circle in the middle and a line drawing from the center out when the mouse moves. I want to calculate the distance from the mouse position to the middle of the circle. What I am going to do is have a sound playing from the center of the ball..The closer you get the louder the sound gets and the further away from the middle the quieter it gets. You can download my fla to see what I have so far.
Is there a way to find the radial distance using the zipcode? My task is to search the all the users residing with in a specified distance. I know the zipcodes of the users. Eg, users between 25 miles from the current location. I have other search categories, for which i am using mysql queries. I am unable to figure anything out for the distance issue.
My backend is in php and frontend in Flex.
The best option for me would be something like that of www.zip-codes.com/zip-code-radius-finder.asp. ie, if I should be able to get all the zip-codes available in the specified radial distance. So i can compare this zip-codes to the users zip-codes in my database. And select the ones with a match.
I have a for loop that arranges icons in rows, and I want 6 icons per row. The number of icons is variable. So I was thinking that if I can find out how to test if a number is a perfect multiple of 6 (or 7, I suppose), I could then add a line in the loop that changes the _y value of the thumb to a higher number and resets the _x value to 0, thereby creating a new line. how do you test to see if a number is round?
im trying to create an image gallery where i place my images randomly over the stage but i want to place the images in the next most empty spot over the stage, for example if all the images somehow have been placed at the right of the stage i want to use math to detect that and find the empty left position .
Im sure there is a math formula to do it , will somebody knows the name for it ? or a link ?
i found this but uses hitTest and thats not efficient and it doesnt finds the big empty spot: [URL]
I want to make a graph. Specifically, a graph of a normal population distribution.I think (please correct me if I'm wrong) that the best way for me to do this is to use two arrays for coordinates and use the lineTo function to connect the dots:
- An Index array up to about 300 as the "x-axis"
- A Second array to represent the "y-axis" created using the formula for normal population applied to each entry of the index array
So I need to create these two arrays in FMX. the first array i think should be created with a For loop: for(i=0;i<a.length;i++){} The second array somehow applying my formula to each entry in array 1.I believe my methods are correct, but I am having a great deal of trouble getting the AS down properly and I can't find many good sources on it.
I am learning AS3 and I try to remake an SimDate game. I have studies the functions and the Steps of the game and now I try to make the Functions myself.
I have 5 Attributes: Strength Knowledge Charm Health Dollars
For each of them I have defined a variable. Now I need to make an math function. If I want to raise str: statusstrenght = statusstrenght + addstr
This code is not the original. My other code is down below. I only wanted to show the process. addstr == Math.random() *5 I wanted that the variable statusstrenght starts with 10. If I press the train Strenghtbutton the action addstr will be started and updates the statusstr with the new value. That's what I had in mind but I cant define the new value off statusstrenght + addstr. Do I have to add a new variable with newstatusstrenght or can I just overwrite the value of statusstrenght if I press the train strength button ?
Here is the code. The math functions aren't working. It is AS3. import flash.events.*; var statusstrenght:Number = 10; var statusknowledge:Number = 10; var statuscharme:Number = 10; var statushealth:uint = 100; var statusdollar:uint = 100; [Code] .....
I have a line that is drawn using the draw api. I need to find points on the line when given the x value, how would I do this. I know on the bezier segment I can just user the yForX() and get the value but not sure how to with just a straight line.
Note: The Math functions acos, asin, atan, atan2, cos, exp, log, pow, sin, and sqrt may result in slightly different values depending on the algorithms used by the CPU or operating system. Flash runtimes call on the CPU (or operating system if the CPU doesn't support floating point calculations) when performing the calculations for the listed functions, and results have shown slight variations depending upon the CPU or operating system in use.
My web application works with very large and small numbers that I suspect may see a difference depending on which machine is running it (especially with mobile devices whose processors aren't as powerful as desktop machines'). My question is, is this behavior a function of the language?
That is, I assume some languages implement their own algorithms for the above functions, and so may be more consistent (except for differences in round-off errors introduced by the choice of processor/CPU that would exist for all languages).
Anyone know if Javascript has it's own algorithms, or does it outsource them to the CPU/processor like ActionScript?
I'm using the TouchEvent listener rather than the TransformGestureEvent listener because the TransformGestureEvent listener's built in gestures (particularly zoom) seem to be extremely slow and poorly thought out. So I'm dealing with raw touch data and I need to find the number of current touchpoints. Is there a method that returns the number of touchpoints currently on the screen?
I installed a Flash template that has a "Read More" button which is used in several locations of the site. The button corresponds to a single symbol called "button_more" and another symbol within that symbol called "area_more". It's a "Movie Clip" type of symbol, not a "Button" type symbol.
What I'm trying to figure out is where would I find the link to the page where that button points to - it points to different pages of the site depending on where it's located. For example, in the About Us section it links to a page that has more details describing About Us. In the Services section it links to a page that has more details describing Services. So the same symbol is going to different links.
I checked the Properties of the symbol and it doesn't have any option for a link. (I guess it's not really going to a link, but to a different frame in the timeline) But where would I find exactly where each button points to in case I want to edit one of them in the future, or create a new button with a new link?