creating geometric objects

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

creating geometric objects

Message par lukamar » mer. févr. 21, 2018 6:12 pm

Hello Bernard,
how can I create a geometric object programmatically in c++? Basically I would like to make representation of a graph, displaying edges as line segments and nodes as ellipses with text inside (2D) or just edges (3D). I believe that's not difficult to do in Giac, but it's hard to learn just by looking to the source code. Can you please explain what functions should I use and how?
Thanks.

Luka

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: creating geometric objects

Message par parisse » mer. févr. 21, 2018 8:26 pm

The easiest is probably to call _-prefixed Xcas commands, like _point(), _segment() and put all the returned values in a list that you return at the end (the C++ functions have French keywords, see doc/fr/keywords for translation). There is no support for text in an ellipse, you can only add text as legend to any geometric object or at a given complex with _legend.
The inner format for graphic expressions is a little bit complicated (this comes from history, some objects have been added), you can look at void fltk_draw(...) in Graph.cc for 2-d and Graph3d::indraw in Graph3d.cc for 3-d, everything graphic is in a symbolic of sommet at_pnt with as feuille a vecteur of 2 or 3 elements
1/ the first element is the object : 2-d: a complex or a line/halfline/segment (2 complexes in a vecteur) or a circle or a curve, 3-d: point (vecteur with 3 coordinates of subtype _POINT__VECT), line/halfline/segment (vecteur of two 3-d points), sphere, hyperplan. curves are symbolic of sommet at_curve and have several arguments (parametric equation, variable, tmin, tmax, sometimes additional informations like cartesian equation or alternate rational parametric equation for conics...)
2/ the second element governs how the object will be displayed (color for example), and also if the object is on a curve.
3/ the last optional element is the legend, it is automatically created by := when you run for example A:=point(1,2)

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: creating geometric objects

Message par lukamar » mer. févr. 21, 2018 10:53 pm

Thanks, I think the easy variant with _segment and _point calls in a list will do just fine.
How to add attributes, for example display=quadrant2 or legend="abc", to _point function? Do i use something like symbolic(at_equal,makevector(...,_QUADRANT2))? (how is "display" defined?)
I noticed that 'point_point' attribute produces no effect. It would be nice if it resulted with a filled dot with the same size as 'square_point'.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: creating geometric objects

Message par parisse » jeu. févr. 22, 2018 7:44 am

symbolic(at_equal,makesequence(at_display,change_subtype(_QUADRANT2,_INT_COLOR)))

point_point drawing code is:

Code : Tout sélectionner

    case 7: // point
      if (epaisseur_point>2)
	fl_arc(deltax+i0-(epaisseur_point-1),deltay+j0-(epaisseur_point-1),2*(epaisseur_point-1),2*(epaisseur_point-1),0,360);
      else
	fl_line(deltax+i0,deltay+j0,deltax+i0+1,deltay+j0);
      break;
it should display a filled dot depending on point_width_n with n=1 to 7

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: creating geometric objects

Message par lukamar » jeu. févr. 22, 2018 9:43 am

parisse a écrit :it should display a filled dot depending on point_width_n with n=1 to 7
Yes, it works when setting point_width_n to a number greater than one.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: creating geometric objects

Message par lukamar » jeu. févr. 22, 2018 1:02 pm

I remember there was a possibility of placing an arrowhead on a curve. In this case I need to place them at centers of the line segments. How can one do this? It would make displaying directed graphs possible.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: creating geometric objects

Message par parisse » jeu. févr. 22, 2018 2:42 pm

For curves, display=arrow_line will add an arrow in the middle, for segments, the analog would be vectors but the arrow will be at the end.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: creating geometric objects

Message par lukamar » jeu. févr. 22, 2018 3:05 pm

OK, the solution is simple: one should draw a vector covering half of the arc and the a segment covering other half. The arrow will appear to be drawn in the middle (almost, since it's the tip which is actually centered).

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: creating geometric objects

Message par parisse » jeu. févr. 22, 2018 3:46 pm

Indeed! Nice trick!

Répondre