You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Hauke Fuhrmann <ha...@informatik.uni-kiel.de> on 2007/03/06 14:00:52 UTC
get x and y values of a path element
Hello there,
is there any possibility to get a list of interpolation points of an
arbitrary SVG Path element?
My task is to move some element along an SVG Path element and therefore
I want to redraw it again and again at the corresponding positions of
the path. Therefore I need the x and y coordinates of the path according
to some input parameter, which could be the percentage of the path
length. E.g. something like
Point getCoords(float percentage);
All methods or classes I found return only --for example-- an array of
the _commands_ rather than actual positions, e.g. the PathArrayProducer.
I hope I can avoid to write my own PathHandler, that interpretes the
path commands.
Best regards,
Hauke
Re: get x and y values of a path element
Posted by Andreas Neumann <ne...@karto.baug.ethz.ch>.
Hi Hauke,
SMIL is a declarative way to define interactivity and animation (doesn't
require scripting but can interact with scripting). It can start an
animation based on another mouse or keyboard event. If you read the
animation chapter in the SVG specification or a SMIL intro you'll get
the idea.
But from what I read regarding your problem it sounds like a combination
of script and SMIL might be required.
With script you can fetch the data (use something like getURL/postURL or
XMLHttpRequest (in browsers)) process the data and then place a little
symbol to where you want it to have, using .getPointAtLength(). The
problem is, that you probably want to auto-orient the symbol according
to the tangent angle at the given point along the curve. As far as I
know there is no scripting way to do this, but the SMIL method
animateTransform can auto orient objects along a path. But luckily you
can create SMIL elements with script and just create a new
animateTransform element and tweak its values.
http://www.eminerllc.com/demos/SVG/Menu.svg has a few examples similar
to what you want to do. Some examples use old, incompatible code made
for the Adobe viewer, but the ones that are marked with the firefox icon
should also run on Batik, Opera and Safari. I think most of the examples
are script based, since Firefox doesn't support SMIL yet.
Hope this helps a little bit,
Andreas
>This sounds quite what I want to do, expect one thing (sorry, I'm an SVG
>newbie, so I'm not exactly sure, what features SMIL provides): as I
>understand, the animations of SMIL are synchronized to time. However I
>need to trigger these animations manually, resp. by some external events.
>For example I want to define a gauge, that displays some sensor value
>that some other program regularly sends to my application. So I need to
>animate the needle of the gauge corresponding to external input and not
>to predefined time. Is it possible to do this with batik (with SMIL?)?
>
>Best regards,
>Hauke
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>
--
----------------------------------------------
Andreas Neumann
Institute of Cartography
ETH Zurich
Wolfgang-Paulistrasse 15
CH-8093 Zurich, Switzerland
Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
e-mail: neumann@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: get x and y values of a path element
Posted by Hauke Fuhrmann <ha...@informatik.uni-kiel.de>.
Andreas Neumann wrote:
> Hope this helps,
Thanks for these hints!
> However, if you just want to move an element along the path, consider
> using SMIL: http://www.w3.org/TR/SVG11/animate.html#AnimateMotionElement
This sounds quite what I want to do, expect one thing (sorry, I'm an SVG
newbie, so I'm not exactly sure, what features SMIL provides): as I
understand, the animations of SMIL are synchronized to time. However I
need to trigger these animations manually, resp. by some external events.
For example I want to define a gauge, that displays some sensor value
that some other program regularly sends to my application. So I need to
animate the needle of the gauge corresponding to external input and not
to predefined time. Is it possible to do this with batik (with SMIL?)?
Best regards,
Hauke
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: get x and y values of a path element
Posted by Andreas Neumann <ne...@karto.baug.ethz.ch>.
yes, there is the method ".getPointAtLength(distance)" at the interface
"SVGPathElement", see also IDL of the SVG 1.1 spec. This is implemented
in all important SVG viewers incl. Batik. See spec:
http://www.w3.org/TR/SVG11/paths.html#DOMInterfaces - there is also the
method .getTotalLength() which returns the path length which you can use
in .getPointAtLength()
However, if you just want to move an element along the path, consider
using SMIL: http://www.w3.org/TR/SVG11/animate.html#AnimateMotionElement
- this is implemented in the SVN version of Batik only, not in the
latest stable release. However, a new stable release will probably
happen soon.
Hope this helps,
Andreas
Hauke Fuhrmann wrote:
>Hello there,
>
>is there any possibility to get a list of interpolation points of an
>arbitrary SVG Path element?
>
>My task is to move some element along an SVG Path element and therefore
>I want to redraw it again and again at the corresponding positions of
>the path. Therefore I need the x and y coordinates of the path according
>to some input parameter, which could be the percentage of the path
>length. E.g. something like
>
>Point getCoords(float percentage);
>
>All methods or classes I found return only --for example-- an array of
>the _commands_ rather than actual positions, e.g. the PathArrayProducer.
>I hope I can avoid to write my own PathHandler, that interpretes the
>path commands.
>
>Best regards,
>Hauke
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
--
----------------------------------------------
Andreas Neumann
Institute of Cartography
ETH Zurich
Wolfgang-Paulistrasse 15
CH-8093 Zurich, Switzerland
Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
e-mail: neumann@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org