Collision Detection on SMIL Animation Path

Discuss SVG code, accessible via the XML Editor.
coiner
Posts: 19
Joined: Mon Mar 14, 2011 5:21 pm
Location: NY

Collision Detection on SMIL Animation Path

Postby coiner » Mon Mar 14, 2011 5:29 pm

I have a thread in JavaScript watching two animated shapes. I would like to detect when they collide but I can't get the current position of the shapes as the animateTransform being processed does not update the shapes' coordinates. How should I go about collision detection with SMIL animates?

schmaltzer
Posts: 4
Joined: Wed Mar 30, 2011 5:36 am

Re: Collision Detection on SMIL Animation Path

Postby schmaltzer » Wed Mar 30, 2011 12:35 pm

When I did this (it was ages ago) I used the fact that one can get the length of a path and the co-ordinates of a point a distance down the path. A quick google search didn't show how to find the latter but if you persevere it is there somewhere.

Good luck!

schmaltzer
Posts: 4
Joined: Wed Mar 30, 2011 5:36 am

Re: Collision Detection on SMIL Animation Path

Postby schmaltzer » Wed Mar 30, 2011 12:40 pm

For locating a point on the path, I'm pretty sure I gave 1 as the length attribute:

http://www.w3.org/TR/SVG/paths.html#DistanceAlongAPath

which is of course bogus but it made everything else easy.

coiner
Posts: 19
Joined: Mon Mar 14, 2011 5:21 pm
Location: NY

Re: Collision Detection on SMIL Animation Path

Postby coiner » Fri Apr 01, 2011 6:21 am

I don't really understand what you mean by this, are you talking about distance along animation paths or a path element? Perhaps an example would make it clear.

As for my own progress on this issue, I've been trying to use the "getBBox()" method of the animated element to obtain its current position in a continuous thread. I haven't had much chance to work on it but when I figure out if that will work I will post the results.

coiner
Posts: 19
Joined: Mon Mar 14, 2011 5:21 pm
Location: NY

Re: Collision Detection on SMIL Animation Path

Postby coiner » Sat Sep 10, 2011 6:50 am

I have (somewhat) solved this issue using the getBBox() method. Although I have not done collision detection, I have successfully found the coordinates of an animated element using getBBox() and getCTM(). Working example follows:

http://static.dorshnik.com/test/point-on-path.svg


Return to “SVG / XML Code”