FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   storing coordinates in a given path?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: storing coordinates in a given path?  (Read 422 times)
dbunder


storing coordinates in a given path?
« on: Aug 26th, 2003, 2:19am »

i'm not sure if this is the right forum to post this in as it is a general mathematical question.  but here goes...
 
i want to record a mouse drag in an applet.  getting the starting and ending positions of the drag is simple.  but i can't seem to recall how to determine what specific coordinates are in the path.  like an exact 45 degree drag from the origin would produce coordinates 0,0 1,1 2,2 and so on up until the endpoint.  obvious.  but what would be a good way to find all the coordinates in any given drag?
 
thanks for any help.
 
-j
 
flight404

WWW Email
Re: storing coordinates in a given path?
« Reply #1 on: Aug 26th, 2003, 5:19am »

Can  you clarify a bit?
 
If you drag the mouse at a 45 degree angle from the upper left to the lower right, in order to get 0,0,1,1,2,2... you would have to be dragging the mouse really slow.  Are you looking to find points that dont necessarily correspond to positions in which the mouse was located?  
 
More specifically, are you looking to have mathematics figure out what points existed between pmouseX, pmouseY and mouseX,mouseY every frame for the duration of the drag?  If so, are you looking to smooth out the path of the mouse travel by using curves?
 
If you are just looking to record the actual mouse positions, I would recommend looking over this example.
 
http://www.proce55ing.net/learning/examples/storing_input.html
 
Here, the mouse position is stored in an array to be used to draw circles.  Just modify it so that mousePress starts the array recording and mouseRelease stops it.
 
Does this help?
 
r
 
 
 
dbunder


Re: storing coordinates in a given path?
« Reply #2 on: Aug 26th, 2003, 11:56pm »

yes this was very helpful.  it was one of the few examples i didn't look at for some reason.  oops
 
on Aug 26th, 2003, 5:19am, flight404 wrote:
Can  you clarify a bit
 
http://www.proce55ing.net/learning/examples/storing_input.html

 
scafativ


Re: storing coordinates in a given path?
« Reply #3 on: Aug 27th, 2003, 1:14am »


Ok,
 
I think I know what you're asking, but if I'm wrong, no offense intended...
 
I think that you're looking for y=mx+b, where m is the slope between the start and endpoint of the drag, and b is the intercept (of the y axis) were that drag to have been extended through the y axis.  This formula is called linear interpolation (or extrapolation, if you want to know what points would be hit were the drag to extend.
 
What you need to do is calculate m and b, and then create a loop with x equaling x-start to x-stop, and figure out each y.
 
A page where this is all described (mathmatically, not programmatically) is:
 
http://schools.spsd.sk.ca/mount/Hoffman/MathC30/LinFin.pdf
 
best of luck.
 
dbunder


Re: storing coordinates in a given path?
« Reply #4 on: Aug 27th, 2003, 6:37am »

yesyes, i was able to do this.  basic algebra and whatnot.  i was attempting to get the points from any sort of drag within the applet.  while this equation would be accurate for a linear drag it wouldn't work for a "scribbly" drag.  i guess what i was asking is if processing implemented any sort of coordinate storage.  i posted before i knew much about the api and whatnot and i probably would've been better off waiting until i read the api reference and tutorials.  bad habit.
 
thanks!
 
-j
 
on Aug 27th, 2003, 1:14am, scafativ wrote:

Ok,
 
I think I know what you're asking, but if I'm wrong, no offense intended...
 
I think that you're looking for y=mx+b, where m is the slope between the start and endpoint of the drag, and b is the intercept (of the y axis) were that drag to have been extended through the y axis.  This formula is called linear interpolation (or extrapolation, if you want to know what points would be hit were the drag to extend.
 
What you need to do is calculate m and b, and then create a loop with x equaling x-start to x-stop, and figure out each y.
 
A page where this is all described (mathmatically, not programmatically) is:
 
http://schools.spsd.sk.ca/mount/Hoffman/MathC30/LinFin.pdf
 
best of luck.

 
Pages: 1 

« Previous topic | Next topic »