Loading ...
Sorry, an error occurred while loading the content.

Re: retrieve shapes coordinates / remove transformations

Expand Messages
  • Francis Hemsher
    Hi Johan, I don t fully understand your need, but let me present a few ideas: Placing elements in a allows you to reference pre/post transform removal via
    Message 1 of 3 , Jun 4, 2009
    • 0 Attachment
      Hi Johan,
      I don't fully understand your need, but let me present a few ideas: Placing elements in a <g> allows you to reference pre/post transform removal via its bounding box locations.

      e.g.
      BEFORE TRANSFORM(translation) REMOVAL
      <g id="circleG">
      <circle id="myCircle" transform="translate(50 50)" cx="0" cy="0" r="20" fill="blue"/>
      </g>

      <g id="rectG">
      <rect id="myRect" transform="translate(50 50)" x="0" y="0" width="20" height="20" fill="red"/>
      </g>

      Ok, let's remove the translations and place the elements, after removing the tranform attribute, at their original position.

      //---the circle---
      var bb=circleG.getBBox()
      var bbx=bb.x
      var bby=bb.y
      var bbw=bb.width
      var bbh=bb.height
      var cx=bbx+.5*bbw
      var cy=bby+.5*bbh

      myCircle.setAttribute("cx",cx)
      myCircle.setAttribute("cy",cy)
      myCircle.removeAttribute("transform")

      //---the rect----
      var bb=rectG.getBBox()
      var bbx=bb.x
      var bby=bb.y

      myRect.setAttribute("x",bbx)
      myRect.setAttribute("y",bby)
      myRect.removeAttribute("transform")


      The elemets will remain at their pre-transform removal location.

      I hope this helps,
      Francis


      <johan.brelet@...> wrote:
      >
      > In fact I need to remove all transformations attributes (translate, rotate, ...) in SVG in order to retrieve shapes exact coordinates.
      > I need this to then calculate shapes intersections/overlaps.
    • Frank Bruder
      ... You can call the element s method getCTM() to retrieve the current transformation matrix resulting from all transformations on it and its ancestor
      Message 2 of 3 , Jun 8, 2009
      • 0 Attachment
        --- In svg-developers@yahoogroups.com, "johan.brelet" <johan.brelet@...> wrote:
        >
        > In fact I need to remove all transformations attributes (translate, rotate, ...) in SVG in order to retrieve shapes exact coordinates.
        >
        You can call the element's method getCTM() to retrieve the current transformation matrix resulting from all transformations on it and its ancestor elements. To apply that transformation you would in some cases have to convert basic shapes to paths. (A scaled and translated rectangle or ellipse is still an ellipse, but if rotated you need a path.) If you want to keep basic shapes as basic shapes whenever possible, there will be a lot of case distinctions to be done. All basic shapes can be converted to equivalent paths.

        When it comes to transforming paths, I have implemented this in the function transformPath in my paths.js at
        <http://frankbruder.fr.ohost.de/FeSVGDoc/>

        It uses some things defined in util.js, especially the function transformEllipse. Transforming ellipses (needed for ellipse, circle, and rect with rounded corners, as well as "a" commands in paths) with general matrizes is rather complicated. It requires calculating eigenvalues and eigenvectors. You probably won't want to figure the math out yourself, so use my code.


        Regards
        Frank
      Your message has been successfully submitted and would be delivered to recipients shortly.