Difference between revisions of "Working with 2Geom FAQ"

From Inkscape Wiki
Jump to navigation Jump to search
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Introduction ==
== Introduction ==


Questions that arise during coding with 2geom are put here. To see other 2geom related questions go to the general [[lib2geom FAQ]].
Questions that arise during coding with 2geom are put here. To see other 2geom related questions go to the general [[lib2geom FAQ]]. Bugs can be reported at SF: [http://sourceforge.net/tracker/?group_id=167845&atid=844560 2geom bug tracker].


== Questions ==
== Questions ==


===How to create a straight line (for types: Path, pwd2, d2pw)?===
===How to create a straight line (for types: Path, pwd2, d2pw)?===
    Path p;
    p.appendNew<LineSegment>(a, b);
   
    Piecewise<D2<SBasis> > pwd2 = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(a[X], b[X]), Linear(a[Y], b[Y])));


===How to convert from Path to pwd2 to d2pw to path and back?===
===How to convert from Path (or PathVector) to pwd2 to d2pw to path and back?===
 
    D2<Piecewise<SBasis> > y;
    Piecewise<D2<SBasis> > x;
    Path p;
    PathVector pvec;
    //Assume the above vars are initialized
    x = p.toPwSb();
    y = make_cuts_independant(x);          // pwd2 -> d2pw
    x = sectionize(y);                    // d2pw -> pwd2
    p = path_from_piecewise(x, tolerance); // pw2d -> path
    x = paths_to_pw(pvec);                // pathvector -> pwd2
 
How do i convert from d2pw to path?


===How do I calculate the bounding box of a path?===
===How do I calculate the bounding box of a path?===
    Rect r = path.boundsFast();
or
    Rect r = path.boundsExact();


===How do I convert 2geom to svgd and back?===
===How do I convert 2geom to svgd and back?===
inkscape has code for this somewhere :(Johan knows this)
    #include "live_effects/n-art-bpath-2geom.h"
    ...
    std::vector<Geom::Path> path_2geom;
    gchar * svgd = SVGD_from_2GeomPath( path_2geom );
    std::vector<Geom::Path> newpath_2geom = SVGD_to_2GeomPath(svgd);
    g_free(svgd);
 
 
===How do I convert from Inkscape paths to 2geom paths?===
    #include "live_effects/n-art-bpath-2geom.h"
    ...
    NArtBpath * path_in;
    std::vector<Geom::Path> path_2geom = BPath_to_2GeomPath(path_in);
    NArtBpath *new_bpath = BPath_from_2GeomPath(path_2geom);
 
===How do I convert from Inkscape points to 2geom points?===
    Geom::Point p_2geom(NR_HUGE, NR_HUGE);
    NR::Point t(p_2geom);
    Geom::Point pother_2geom = t.to_2geom();


===What does "compose" do?===
===What does "compose" do?===
(i keep forgetting)
[http://en.wikipedia.org/wiki/Function_composition Compose] is the mathematical operation f(?) o g(?) = f(g(?)).  Any transformation, be it translation or mesh distort, can be considered a composition of the original path P(t)->(u,v) and a function T(u,v)->(x,y) which takes each point in the plane to a new point.  We write this transformation as compose(T, P).  For examples of such composition at work look at the toys
 
* '2dsb2d', which composes the path with a polynomial mesh function called a coons patch
* 'plane3d', which composes the path with a 3d projection onto a plane surface
* 'center-warp', which shows how repeated composition produces the tweak tool effect
* 'path-along-path' which shows how composition allows mapping a shape along a path
 
===A dot product ?===
the dot() function is here for you.
    point1 = Geom::Point(10,2);
    point2 = Geom::Point(0,1);
    dot(point1,point2);        // = 2
 
 
2Geom provides various compose operations for functions representable using piecewise sbasis functions, as well the ability to compose arbitrary functions defined directly in code.  All the mathematics is performed in sbasis space.

Revision as of 11:19, 18 August 2008

Introduction

Questions that arise during coding with 2geom are put here. To see other 2geom related questions go to the general lib2geom FAQ. Bugs can be reported at SF: 2geom bug tracker.

Questions

How to create a straight line (for types: Path, pwd2, d2pw)?

   Path p;
   p.appendNew<LineSegment>(a, b);
   
   Piecewise<D2<SBasis> > pwd2 = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(a[X], b[X]), Linear(a[Y], b[Y])));

How to convert from Path (or PathVector) to pwd2 to d2pw to path and back?

   D2<Piecewise<SBasis> > y;
   Piecewise<D2<SBasis> > x;
   Path p;
   PathVector pvec;
   //Assume the above vars are initialized
   x = p.toPwSb();
   y = make_cuts_independant(x);          // pwd2 -> d2pw
   x = sectionize(y);                     // d2pw -> pwd2
   p = path_from_piecewise(x, tolerance); // pw2d -> path
   x = paths_to_pw(pvec);                 // pathvector -> pwd2

How do i convert from d2pw to path?

How do I calculate the bounding box of a path?

   Rect r = path.boundsFast(); 

or

   Rect r = path.boundsExact();

How do I convert 2geom to svgd and back?

   #include "live_effects/n-art-bpath-2geom.h"
   ...
   std::vector<Geom::Path> path_2geom;
   gchar * svgd = SVGD_from_2GeomPath( path_2geom );
   std::vector<Geom::Path> newpath_2geom = SVGD_to_2GeomPath(svgd);
   g_free(svgd);


How do I convert from Inkscape paths to 2geom paths?

   #include "live_effects/n-art-bpath-2geom.h"
   ...
   NArtBpath * path_in;
   std::vector<Geom::Path> path_2geom = BPath_to_2GeomPath(path_in);
   NArtBpath *new_bpath = BPath_from_2GeomPath(path_2geom);

How do I convert from Inkscape points to 2geom points?

   Geom::Point p_2geom(NR_HUGE, NR_HUGE);
   NR::Point t(p_2geom);
   Geom::Point pother_2geom = t.to_2geom();

What does "compose" do?

Compose is the mathematical operation f(?) o g(?) = f(g(?)). Any transformation, be it translation or mesh distort, can be considered a composition of the original path P(t)->(u,v) and a function T(u,v)->(x,y) which takes each point in the plane to a new point. We write this transformation as compose(T, P). For examples of such composition at work look at the toys

  • '2dsb2d', which composes the path with a polynomial mesh function called a coons patch
  • 'plane3d', which composes the path with a 3d projection onto a plane surface
  • 'center-warp', which shows how repeated composition produces the tweak tool effect
  • 'path-along-path' which shows how composition allows mapping a shape along a path

A dot product ?

the dot() function is here for you.

   point1 = Geom::Point(10,2);
   point2 = Geom::Point(0,1);
   dot(point1,point2);         // = 2


2Geom provides various compose operations for functions representable using piecewise sbasis functions, as well the ability to compose arbitrary functions defined directly in code. All the mathematics is performed in sbasis space.