Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com cartesian coordinate system, calc change in position

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 05-30-2011, 02:52 PM PM User | #1 BubikolRamios Senior Coder   Join Date: Dec 2005 Location: Slovenia Posts: 1,926 Thanks: 118 Thanked 76 Times in 76 Posts cartesian coordinate system, calc change in position Need to know if an object moved, from x1 to x2, for how much and in which direction For our case say that y = 0. examples Code: ```x1 x2 expected result 1 -1 -2 1 2 1 -1 -2 -1 -1 -3 -2 6 7 1 7 6 -1 etc``` The simplest way to calc that ? __________________ Found a flower or bug and don't know what it is ? agrozoo.net galery if you don't spot search button at once, there is search form: agrozoo.net galery search Last edited by BubikolRamios; 05-30-2011 at 03:02 PM..
 05-30-2011, 03:49 PM PM User | #2 BWiz Regular Coder     Join Date: Mar 2006 Location: Sol System Posts: 471 Thanks: 7 Thanked 21 Times in 21 Posts Well if y is always zero, then the distance traveled will always be x_final - x_initial. The sign of the answer will tell you whether your moved in the +x direction or the -x direction. If your y changes, however, you'll have to use the distance formula to calculate the MAGNITUDE of the distance. To get the direction and magnitude, I would use vectors, and their respective operations. __________________ BWiz :: Happy Coding! 2006 2007 2008 2009 2010 2011 Irrational numbers make no sense.
 05-30-2011, 04:55 PM PM User | #3 bobleny Regular Coder     Join Date: May 2007 Posts: 256 Thanks: 3 Thanked 11 Times in 11 Posts If both your Y and X coordinates change, you can just use the Pythagorean theorem (a2 + b2 = c2) where the difference in X is your a and the difference in Y is your b. Then solve for c and you have your distance between the two points. Code: ```Point 1 (-1, 0) Point 2 (2, 4) |-1 - 2| = a = 3 |0 - 4| = b = 4 a squared = 9 b squared = 16 9 + 16 = c = 25 The square root of 25 = 5``` The distance between Point 1 and Point 2 is 5. __________________ --www.firemelt.net-- * No good deed goes unpunished. * Cheer up, the worst has yet to come... Get Firefox!
05-31-2011, 02:57 AM   PM User | #4
bullant
Banned

Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
Quote:
 Originally Posted by BubikolRamios Need to know if an object moved, from x1 to x2, for how much and in which direction For our case say that y = 0. examples Code: ```x1 x2 expected result 1 -1 -2 1 2 1 -1 -2 -1 `-1 -3 -2` 6 7 1 7 6 -1 etc``` The simplest way to calc that ?
deltaX = x2 - x1 where deltaX is the distance moved on the x axis.

Bear in mind that subtracting a negative number is the same as adding the absolute value of that number.

If you take the highlighted xample:

deltaX = x2 - x1 = -3 - (-1) = -3 + 1 = -2

If deltaX is negative (less than 0), the object moved in the negative direction on the x axis. If deltaX is positive, the object moved in the positive direction on the x axis.

If the object moves on the y axis as well, then as bobleny described, you can use Pythagoras' Theorem to solve for the straight line distance between 2 points.

distance = sqrt(deltaX^2 + deltaY^2)

In bobleny's example there needs to be a minor correction

Code:
`9 + 16 = c^2 = 25`

Last edited by bullant; 05-31-2011 at 03:10 AM..

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:59 PM.