We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › bouncing at arbitrary curves
Page Index Toggle Pages: 1
bouncing at arbitrary curves (Read 408 times)
bouncing at arbitrary curves
May 28th, 2009, 12:34pm
 
Hello everybody,

I'm quite new to processing but I try to learn...

You probably all know the simple example of a ball bouncing of the frame of a window. Or bouncing of another ball.
(as an example see the second or third post of hxxp://processing.org/discourse/yabb2/num_1167889216__Sorry__I_am_not_allowed_to_post_links_yet_.html

My problem is the following:
I would like to make a ball being reflected from an arbitrary object.
For example a black bat that I paint as a .gif image with transparent background.
How can I get the coordinates of all black pixels inside the .gif
I know how to find the black ones (looking for all pixels with appropriate color information), but can't get the coordinates.

The next step is then to calculate the normal vector to the surface of the bat at the point where the ball is hitting it and applying a formula for reflections.

Or is this complete idea too complicated and can be done much easier I'm not used to all simplifications processing is offering...

Thank you in advance!

Min0r

Re: bouncing at arbitrary curves
Reply #1 - May 29th, 2009, 3:24am
 
By being reflected, I suppose you mean rebounding.

When you scan the image's pixels, you can do it by using x and y coordinates inside the image. Just add the image's coordinates to them and you find the coordinates of the pixel relative to the sketch area.

Now, to find the normal vector is not a simple task: it can be assimilated to vectorizing the image (detecting the contour), which is a hard problem, even if simplifying the task with high contrast and simple shapes.
It can be done, of course, but perhaps it might be simpler to do this vectorization by hand, per image, and enter the data as constants in the program.
Page Index Toggle Pages: 1