Arrow3

Pour toute demande d'aide sur des exemples non finalisés, c'est ici.
Les exemples aboutis et intéressants seront ajoutés aux sous-forums qui suivent.

Règles du forum
Pour toute demande d'aide pour la conception (ou la confirmation d'un code) d'une figure Asymptote, c'est ici.

J'invite ceux qui ont régulièrement des questions à poser à aller dans leur panneau de l'utilisateur pour indiquer dans la signature de leurs messages :

  1. Nom du système d'exploitation (W7 ou Ubuntu 12.04 ou ...)
  2. Version d'Asymptote et éditeur utilisé pour les figures Asymptote
  3. Distribution LaTeX et éditeur utilisé pour les tex.


On va gagner du temps dans les réponses !
Pascal
Messages : 4
Enregistré le : sam. 24 avr. 2021, 12:09

Arrow3

Message non lu par Pascal » ven. 7 mai 2021, 21:31

Il y a plusieurs flèches disponibles dans Asymptote. Je me demande comment je pourrais obtenir une "flèche" ressemblant à ceci : elle commence et se termine par une barre, il y a une flèche à la fin, mais il n'y a pas de ligne droite. (Motivation : Misner, Thorne, Wheeler utilisent ceci dans leur livre Relativité Générale pour dessiner un covecteur par opposition à un vecteur).
Debian Gnu / Linux 9 (stretch); Asymptote 2.38; texlive 2016.20170123-5

Avatar du membre
GM
Administrateur du site
Administrateur du site
Messages : 1512
Enregistré le : dim. 7 mars 2010, 14:50

Re: Arrow3

Message non lu par GM » sam. 8 mai 2021, 09:41

Bonjour,
merci de fournir une image qui montre une telle flèche.

On doit à OG ceci :

Code : Tout sélectionner

void bracket(picture pic, pair a, pair d, real s,pen p=currentpen)
{
  picture opic;
  pair ortd=s*(-d.y,d.x);
  Draw(opic,(ortd-.5d)--(-0.5d)--0.5d--(.5d+ortd),p+solid);
  add(pic,opic,a);
}
arrowbar BeginBra(real size=0, real ratiob=.3)
{
  return new bool(picture pic, path g, pen p, margin margin) {
real size=size == 0 ? barsize(p) : size;
bracket(pic,point(g,0),size*dir(g,0)*I,ratiob,p);
return true;
  };
}
arrowbar Bra(real size=0, real ratiob=.3)
{
  return new bool(picture pic, path g, pen p, margin margin) {
int L=length(g);
real size=size == 0 ? barsize(p) : size;
bracket(pic,point(g,L),size*dir(g,L)*I,-ratiob,p);
return true;
  };
}
arrowbar EndBra(real size=0, real ratiob=.3)= Bra;

arrowbar Bras(real size=0,real ratiob=.3)
{
  return new bool(picture pic, path g, pen p, margin margin) {
real size=size == 0 ? barsize(p) : size;
BeginBra(size,ratiob)(pic,g,p,margin);
EndBra(size,ratiob)(pic,g,p,margin);
return true;
  };
}
arrowbar BeginBra=BeginBra(),
Bra=Bra(),
EndBra=Bra(),
Bras=Bras();
pour permettre cela

Figure asymptote e37d290a86d43bf2efde6b080afe9087
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1. import OG; // pour profiter de "Bras" : extrémités de segment en forme de crochets.
  2.  
  3. unitsize(1cm,0);
  4.  
  5. draw((0,1)--(5,0),Bra);
  6. draw((0,.5)--(5,-.5),BeginBra);
  7. draw((0,0)--(5,-1),EndBra);
  8. draw((0,-.5)--(5,-1.5),Bras);
  9. shipout(bbox(5mm,white));


Donc à voir si on peut s'en inspirer... mais il n'a changé que les extrémités donc à voir par quoi doit être remplacé le segment.
Index des fonctions - Exemple de lien donnant le résultat d'une recherche sur les mots 'arc' et 'triple' : http://asy.marris.fr/indexasy/?filtre=arc triple
Mes configurations (le 24/02/21) :
PC n°1 :Windows 10 - Asymptote(2.82)+MikTeX2.9 - Editeurs : Notepad++, TeXworks, Visual Studio Code.
PC n°2 : Ubuntu 20.04LTS - Asymptote(2.67-?? git) + TexLive2020
Mon serveur : Debian Stretch- Asymptote(2.68-16 git) + TexLive2018
Merci de préciser la votre !

Avatar du membre
GM
Administrateur du site
Administrateur du site
Messages : 1512
Enregistré le : dim. 7 mars 2010, 14:50

Re: Arrow3

Message non lu par GM » sam. 8 mai 2021, 15:48

GM a écrit :
sam. 8 mai 2021, 09:41
... donc à voir par quoi doit être remplacé le segment.
Il devrait être possible de bricoler quelque chose inspiré de cela :

Figure asymptote 26aaa399118b6d9a20fd32ff050f71b2
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1. path ondulation(path g, real step=4, real distance=1)
  2. {
  3. real len = arclength(g);
  4. int state = 0;
  5. guide zig;
  6. for (real u = 0; u < len; u += step) {
  7. real t= arctime(g, u);
  8. pair p = point(g, t);
  9. pair norm = unit(rotate(90) * dir(g, t));
  10. if(u<.1*len || u>=.9*len){
  11. zig = zig -- p;
  12. }else{
  13. if (state == 1)
  14. p = p + distance * norm;
  15. else if (state == 3)
  16. p = p - distance * norm;
  17. zig = zig .. p;
  18. }
  19. state = (state + 1) % 4;
  20. }
  21. zig = zig .. point(g, length(g));
  22. return zig;
  23. }
  24.  
  25. // test
  26. draw(ondulation((0,0) -- (4cm,2cm)),red,Arrow);
  27. draw(ondulation((0,0) -- (6cm,-2cm)),blue,Arrow(SimpleHead));
Index des fonctions - Exemple de lien donnant le résultat d'une recherche sur les mots 'arc' et 'triple' : http://asy.marris.fr/indexasy/?filtre=arc triple
Mes configurations (le 24/02/21) :
PC n°1 :Windows 10 - Asymptote(2.82)+MikTeX2.9 - Editeurs : Notepad++, TeXworks, Visual Studio Code.
PC n°2 : Ubuntu 20.04LTS - Asymptote(2.67-?? git) + TexLive2020
Mon serveur : Debian Stretch- Asymptote(2.68-16 git) + TexLive2018
Merci de préciser la votre !

Avatar du membre
GM
Administrateur du site
Administrateur du site
Messages : 1512
Enregistré le : dim. 7 mars 2010, 14:50

Re: Arrow3

Message non lu par GM » sam. 8 mai 2021, 15:51

Oups... je viens de réaliser que le titre est "Arrow3".
Si c'est une flèche spéciale pour une figure 3D qu'il faut, cela va nettement se compliquer.
Index des fonctions - Exemple de lien donnant le résultat d'une recherche sur les mots 'arc' et 'triple' : http://asy.marris.fr/indexasy/?filtre=arc triple
Mes configurations (le 24/02/21) :
PC n°1 :Windows 10 - Asymptote(2.82)+MikTeX2.9 - Editeurs : Notepad++, TeXworks, Visual Studio Code.
PC n°2 : Ubuntu 20.04LTS - Asymptote(2.67-?? git) + TexLive2020
Mon serveur : Debian Stretch- Asymptote(2.68-16 git) + TexLive2018
Merci de préciser la votre !

Pascal
Messages : 4
Enregistré le : sam. 24 avr. 2021, 12:09

Re: Arrow3

Message non lu par Pascal » sam. 15 mai 2021, 19:47

Merci beaucoup pour ces exemples. Pour 2D cela m'avance.
En fait, j'avais préparé une solution pour 2D que je joins ici.

Oui, en effet je cherche (aussi) une solution 3D.
Ce que j'aimerais savoir, au niveau d'Asymptote, c'est si il est possible de modifier une fonction comme Arrow3. Ou si il est possible de programmer une fonction semblable mais en évitant de programmer tous les élements à un niveau élémentaire (comme je le fais).

Je vais étudier les exemples parce que j'ai l'impression qu'ils vont m'apprendre cela.
Pascal

Figure asymptote 11263d63a670a24b7a1d92d0de5566e0
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1.  
  2. // Visualizing Differential Geometry
  3. // Draw 1-form
  4. //
  5. // Exercise from Tu, An Introduction to Manifolds, Exercises 4.9
  6.  
  7. import graph;
  8. // Size of the drawing. Unit are "big points", a big point is 1/72 inch
  9. // If you give 2 arguments then this will be breadth and height
  10. // size(100) yields a quadratic drawing with more than 1 inch (2.54 cm) edge length
  11. size(400);
  12.  
  13. real gridsize = 1.0;
  14. int igridsize = 1;
  15. real max=10;
  16. int imax=10;
  17. // Length of the bar at the starting and end point of the covector.
  18. real bl=gridsize*2/10;
  19.  
  20. // Debug (*)
  21. pair DebugPoint=(-2,-2);
  22. // Debug (+)
  23.  
  24. // Labels
  25. label("-10,-10",(-11,-11),SW,fontsize(6pt));
  26. label("10,-10",(11,-11),SE,fontsize(6pt));
  27. label("10,10",(11,11),NE,fontsize(6pt));
  28. label("-10,10",(-11,11),NW,fontsize(6pt));
  29. //
  30. xaxis("$u$", xmin=-max*1.3,xmax=max*1.3,EndArrow);
  31. yaxis("$v$", ymin=-max*1.3,ymax=max*1.3,EndArrow);
  32.  
  33. // Compute covector components as a function of x and y.
  34. // This is from the textbook Exercise 4.9
  35.  
  36. real omegax(real x, real y) {
  37. return (-y/(x**2+y**2));
  38. }
  39. real omegay(real x, real y) {
  40. return (x/(x**2+y**2));
  41. }
  42.  
  43. pair covectorStartpoint(pair p) {
  44. return (p.x,p.y);
  45. }
  46.  
  47. pair covectorEndpoint(pair p) {
  48. return (p.x+omegax(p.x, p.y),p.y+omegay(p.x, p.y));
  49. }
  50.  
  51. real covectorAngleX(pair p) {
  52. if (omegax(p.x, p.y)==0) {
  53. if (omegay(p.x, p.y)>0)
  54. // covector points north
  55. return pi/2;
  56. else
  57. // covector points south
  58. return 3*pi/2;
  59. }
  60. else {
  61. if (omegax(p.x, p.y) > 0 && omegay(p.x, p.y) > 0) {
  62. // covector points northeast
  63. return atan (omegay(p.x, p.y) / omegax(p.x, p.y));
  64. }
  65. else if (omegax(p.x, p.y) < 0 && omegay(p.x, p.y) > 0) {
  66. // covector points northwest
  67. return (pi + atan (omegay(p.x, p.y) / omegax(p.x, p.y)));
  68. }
  69. else if (omegax(p.x, p.y) < 0 && omegay(p.x, p.y) < 0) {
  70. // covector points southwest
  71. return (pi + atan (omegay(p.x, p.y) / omegax(p.x, p.y)));
  72. }
  73. else if (omegax(p.x, p.y) > 0 && omegay(p.x, p.y) < 0) {
  74. // covector points southeast
  75. return (2*pi + atan (omegay(p.x, p.y) / omegax(p.x, p.y)));
  76. }
  77. else
  78. return 0;
  79. }
  80. }
  81.  
  82. pair covectorHalfBarLengthFromEndpoint(pair p) {
  83. real covectorTangens;
  84. real Dx;
  85. real Dy, DyAbsolute;
  86. if (omegax(p.x, p.y) != 0) {
  87. if (omegay(p.x, p.y) != 0) {
  88. covectorTangens=omegay(p.x, p.y)/omegax(p.x, p.y);
  89.  
  90. DyAbsolute=sqrt((covectorTangens^2 * (bl/2)^2) / (1 + covectorTangens^2));
  91. if (0 < covectorAngleX(p) && covectorAngleX(p) < pi/2) {
  92. Dy=-DyAbsolute;
  93. Dx=Dy/covectorTangens;
  94.  
  95. } else if (pi/2 < covectorAngleX(p) && covectorAngleX(p) < pi) {
  96. Dy=-DyAbsolute;
  97. Dx=Dy/covectorTangens;
  98. } else if (pi < covectorAngleX(p) && covectorAngleX(p) < 3*pi/2) {
  99. Dy=DyAbsolute;
  100. Dx=Dy/covectorTangens;
  101. } else if (3*pi/2 < covectorAngleX(p) && covectorAngleX(p) < 2*pi) {
  102. Dy=DyAbsolute;
  103. Dx=DyAbsolute/covectorTangens;
  104. }
  105. // Debug (*)
  106. //if (p == DebugPoint) {
  107. //write(p, covectorEndpoint(p), covectorAngleX(p), Dx, Dy, DyAbsolute);
  108. //}
  109. // Debug (+)
  110. return (covectorEndpoint(p).x+Dx,covectorEndpoint(p).y+Dy);
  111. } else { // horizontal covector
  112. if (covectorEndpoint(p).x < p.x)
  113. // covector points left
  114. return (covectorEndpoint(p).x+bl/2,covectorEndpoint(p).y);
  115. else
  116. return (covectorEndpoint(p).x-bl/2,covectorEndpoint(p).y);
  117. }
  118. } else { // vertical covector
  119. if (covectorEndpoint(p).y < p.y)
  120. // covector points down
  121. return (covectorEndpoint(p).x,covectorEndpoint(p).y+bl/2);
  122. else
  123. return (covectorEndpoint(p).x,covectorEndpoint(p).y-bl/2);
  124. }
  125. }
  126.  
  127. path arrowLeftpart(pair p) {
  128. real phi=covectorAngleX(p);
  129. return (
  130. (
  131. (covectorEndpoint(p).x-(bl/2)*sin(phi) + covectorHalfBarLengthFromEndpoint(p).x) / 2,
  132. (covectorEndpoint(p).y+(bl/2)*cos(phi) + covectorHalfBarLengthFromEndpoint(p).y) / 2
  133. )--( covectorEndpoint(p) )
  134. );
  135. }
  136.  
  137. path arrowRightpart(pair p) {
  138. real phi=covectorAngleX(p);
  139. return (
  140. (
  141. (covectorEndpoint(p).x+(bl/2)*sin(phi) + covectorHalfBarLengthFromEndpoint(p).x) / 2,
  142. (covectorEndpoint(p).y-(bl/2)*cos(phi) + covectorHalfBarLengthFromEndpoint(p).y) / 2
  143. )--( covectorEndpoint(p) )
  144. );
  145. }
  146.  
  147. path covector(pair p) {
  148. return covectorStartpoint(p)--covectorEndpoint(p);
  149. }
  150.  
  151. real covectorLength(pair p) {
  152. return sqrt(omegax(p.x, p.y)^2+omegay(p.x, p.y)^2);
  153. }
  154.  
  155. // covector is made of
  156. // - bar at start point
  157. // - bar at end point
  158. // - arrow at end point.
  159. // The bars are like short segments from level curves showing increase of function value by 1.
  160. // If the bars are close to each other, the function is steep here.
  161. // If tha bars are far from each other, the function changes slowly.
  162. path covectorStartbar(pair p) {
  163. // Angle of covector with x-axis
  164. real phi=covectorAngleX(p);
  165. // draw straight line between start point and end point of the bar
  166. return ( (p.x-(bl/2)*sin(phi),p.y+(bl/2)*cos(phi))--(p.x+(bl/2)*sin(phi),p.y-(bl/2)*cos(phi)) );
  167. }
  168.  
  169. path covectorEndbar(pair p) {
  170. // Angle of covector with x-axis
  171. real phi=covectorAngleX(p);
  172. // draw straight line between start point and end point of the bar
  173. return ( (covectorEndpoint(p).x-(bl/2)*sin(phi),covectorEndpoint(p).y+(bl/2)*cos(phi))--(covectorEndpoint(p).x+(bl/2)*sin(phi),covectorEndpoint(p).y-(bl/2)*cos(phi)) );
  174. }
  175.  
  176. // 1-form is a set of covectors defined for any point in the plane
  177. // it is similar to a vectorfield.
  178. //
  179. // We follow a suggestion by Misner, Thorne, Wheeler: Gravity.
  180. // They do not draw a straight line between start and end point.
  181. // Instead they draw two bars and a little arrow at the end point.
  182. //
  183. // We evaluate the covectors on a grid
  184. for(int ix=-imax; ix<=imax; ix=ix+igridsize) {
  185. for (int iy=-imax; iy<=imax; iy=iy+igridsize) {
  186. if (ix != 0 || iy != 0) {
  187. pair point=(ix,iy);
  188. draw(covectorStartbar(point));
  189. draw(covectorEndbar(point));
  190. draw(covectorEndpoint(point),red);
  191. // test
  192. // draw(covectorHalfBarLengthFromEndpoint(point),green);
  193. draw(arrowLeftpart(point));
  194. draw(arrowRightpart(point));
  195. // Debug (*)
  196. // if (point == DebugPoint) {
  197. // write(point, covectorHalfBarLengthFromEndpoint(point));
  198. // }
  199. // Debug (+)
  200. // draw(covector(point));
  201. }
  202. }
  203. }
  204.  
Debian Gnu / Linux 9 (stretch); Asymptote 2.38; texlive 2016.20170123-5

Avatar du membre
GM
Administrateur du site
Administrateur du site
Messages : 1512
Enregistré le : dim. 7 mars 2010, 14:50

Re: Arrow3

Message non lu par GM » sam. 15 mai 2021, 22:46

Bonsoir,
j'ai du mal à comprendre ce que je vois : si cela ressemble aux flèches qui étaient demandées, je n'avais pas compris ce qui était attendu.

-----------
Pour la question sur Arrow3, je déconseille de modifier une fonction existante.

On peut selon le cas :
- créer une surcharge d'une fonction (c'est à dire créer des fonctions de même nom avec des signatures différentes)
ou alors
- créer une fonction modifiée avec un nom différent.

-----------
La définition de Arrow3(), dans three_arrows.asy est :

Code : Tout sélectionner

arrowbar3 Arrow3(arrowhead3 arrowhead=DefaultHead3,
                 real size=0, real angle=arrowangle,
                 filltype filltype=null, position position=EndPoint,
                 material arrowheadpen=nullpen)
{
  return new bool(picture pic, path3 g, material p, margin3 margin,
                  light light, light arrowheadlight) {
    add(pic,arrowhead,size,angle,filltype,position,arrowheadpen,g,p,margin,
        light,arrowheadlight);
    return false;
  };
}
... et dans ce même fichier, on trouve les définitions (très compliquées, pour ne pas dire effrayantes) des styles de pointes de flèches :
DefaultHead3, HookHead3, TeXHead3, DefaultHead2, HookHead2, TeXHead2.
Index des fonctions - Exemple de lien donnant le résultat d'une recherche sur les mots 'arc' et 'triple' : http://asy.marris.fr/indexasy/?filtre=arc triple
Mes configurations (le 24/02/21) :
PC n°1 :Windows 10 - Asymptote(2.82)+MikTeX2.9 - Editeurs : Notepad++, TeXworks, Visual Studio Code.
PC n°2 : Ubuntu 20.04LTS - Asymptote(2.67-?? git) + TexLive2020
Mon serveur : Debian Stretch- Asymptote(2.68-16 git) + TexLive2018
Merci de préciser la votre !

Pascal
Messages : 4
Enregistré le : sam. 24 avr. 2021, 12:09

Re: Arrow3

Message non lu par Pascal » sam. 15 mai 2021, 23:21

Hammerlindl, 2020, p. 125-126 montre un "vectorfield", un champ de vecteurs. Ce que je fais dans le petit programme plus haut est très semblable. La seule différence: au lieu de dessiner un vecteur comme chacun le connait, je dessine un "BeginBar", un "EndBar" et puis un "EndArrow". Mais je ne dessine pas de ligne droite.
Debian Gnu / Linux 9 (stretch); Asymptote 2.38; texlive 2016.20170123-5

Avatar du membre
GM
Administrateur du site
Administrateur du site
Messages : 1512
Enregistré le : dim. 7 mars 2010, 14:50

Re: Arrow3

Message non lu par GM » sam. 15 mai 2021, 23:24

Je comprends mieux ainsi, en réduisant le nombre de "flèches" et en mettant un peu de couleur :

Figure asymptote 7f7fe8d3c10a17cd9f74f92f8a80a86c
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1. // Visualizing Differential Geometry
  2. // Draw 1-form
  3. //
  4. // Exercise from Tu, An Introduction to Manifolds, Exercises 4.9
  5.  
  6. import graph;
  7. // Size of the drawing. Unit are "big points", a big point is 1/72 inch
  8. // If you give 2 arguments then this will be breadth and height
  9. // size(100) yields a quadratic drawing with more than 1 inch (2.54 cm) edge length
  10. size(400);
  11.  
  12. real gridsize = 1.0;
  13. int igridsize = 1;
  14. real max=2;
  15. int imax=2;
  16. // Length of the bar at the starting and end point of the covector.
  17. real bl=gridsize*2/10;
  18.  
  19. // Debug (*)
  20. pair DebugPoint=(-2,-2);
  21. // Debug (+)
  22.  
  23. // Labels
  24. // label("-10,-10",(-11,-11),SW,fontsize(6pt));
  25. // label("10,-10",(11,-11),SE,fontsize(6pt));
  26. // label("10,10",(11,11),NE,fontsize(6pt));
  27. // label("-10,10",(-11,11),NW,fontsize(6pt));
  28. //
  29. xaxis("$u$", xmin=-max*1.3,xmax=max*1.3,EndArrow);
  30. yaxis("$v$", ymin=-max*1.3,ymax=max*1.3,EndArrow);
  31.  
  32. // Compute covector components as a function of x and y.
  33. // This is from the textbook Exercise 4.9
  34.  
  35. real omegax(real x, real y) {
  36. return (-y/(x**2+y**2));
  37. }
  38. real omegay(real x, real y) {
  39. return (x/(x**2+y**2));
  40. }
  41.  
  42. pair covectorStartpoint(pair p) {
  43. return (p.x,p.y);
  44. }
  45.  
  46. pair covectorEndpoint(pair p) {
  47. return (p.x+omegax(p.x, p.y),p.y+omegay(p.x, p.y));
  48. }
  49.  
  50. real covectorAngleX(pair p) {
  51. if (omegax(p.x, p.y)==0) {
  52. if (omegay(p.x, p.y)>0)
  53. // covector points north
  54. return pi/2;
  55. else
  56. // covector points south
  57. return 3*pi/2;
  58. }
  59. else {
  60. if (omegax(p.x, p.y) > 0 && omegay(p.x, p.y) > 0) {
  61. // covector points northeast
  62. return atan (omegay(p.x, p.y) / omegax(p.x, p.y));
  63. }
  64. else if (omegax(p.x, p.y) < 0 && omegay(p.x, p.y) > 0) {
  65. // covector points northwest
  66. return (pi + atan (omegay(p.x, p.y) / omegax(p.x, p.y)));
  67. }
  68. else if (omegax(p.x, p.y) < 0 && omegay(p.x, p.y) < 0) {
  69. // covector points southwest
  70. return (pi + atan (omegay(p.x, p.y) / omegax(p.x, p.y)));
  71. }
  72. else if (omegax(p.x, p.y) > 0 && omegay(p.x, p.y) < 0) {
  73. // covector points southeast
  74. return (2*pi + atan (omegay(p.x, p.y) / omegax(p.x, p.y)));
  75. }
  76. else
  77. return 0;
  78. }
  79. }
  80.  
  81. pair covectorHalfBarLengthFromEndpoint(pair p) {
  82. real covectorTangens;
  83. real Dx;
  84. real Dy, DyAbsolute;
  85. if (omegax(p.x, p.y) != 0) {
  86. if (omegay(p.x, p.y) != 0) {
  87. covectorTangens=omegay(p.x, p.y)/omegax(p.x, p.y);
  88.  
  89. DyAbsolute=sqrt((covectorTangens^2 * (bl/2)^2) / (1 + covectorTangens^2));
  90. if (0 < covectorAngleX(p) && covectorAngleX(p) < pi/2) {
  91. Dy=-DyAbsolute;
  92. Dx=Dy/covectorTangens;
  93.  
  94. } else if (pi/2 < covectorAngleX(p) && covectorAngleX(p) < pi) {
  95. Dy=-DyAbsolute;
  96. Dx=Dy/covectorTangens;
  97. } else if (pi < covectorAngleX(p) && covectorAngleX(p) < 3*pi/2) {
  98. Dy=DyAbsolute;
  99. Dx=Dy/covectorTangens;
  100. } else if (3*pi/2 < covectorAngleX(p) && covectorAngleX(p) < 2*pi) {
  101. Dy=DyAbsolute;
  102. Dx=DyAbsolute/covectorTangens;
  103. }
  104. // Debug (*)
  105. //if (p == DebugPoint) {
  106. //write(p, covectorEndpoint(p), covectorAngleX(p), Dx, Dy, DyAbsolute);
  107. //}
  108. // Debug (+)
  109. return (covectorEndpoint(p).x+Dx,covectorEndpoint(p).y+Dy);
  110. } else { // horizontal covector
  111. if (covectorEndpoint(p).x < p.x)
  112. // covector points left
  113. return (covectorEndpoint(p).x+bl/2,covectorEndpoint(p).y);
  114. else
  115. return (covectorEndpoint(p).x-bl/2,covectorEndpoint(p).y);
  116. }
  117. } else { // vertical covector
  118. if (covectorEndpoint(p).y < p.y)
  119. // covector points down
  120. return (covectorEndpoint(p).x,covectorEndpoint(p).y+bl/2);
  121. else
  122. return (covectorEndpoint(p).x,covectorEndpoint(p).y-bl/2);
  123. }
  124. }
  125.  
  126. path arrowLeftpart(pair p) {
  127. real phi=covectorAngleX(p);
  128. return (
  129. (
  130. (covectorEndpoint(p).x-(bl/2)*sin(phi) + covectorHalfBarLengthFromEndpoint(p).x) / 2,
  131. (covectorEndpoint(p).y+(bl/2)*cos(phi) + covectorHalfBarLengthFromEndpoint(p).y) / 2
  132. )--( covectorEndpoint(p) )
  133. );
  134. }
  135.  
  136. path arrowRightpart(pair p) {
  137. real phi=covectorAngleX(p);
  138. return (
  139. (
  140. (covectorEndpoint(p).x+(bl/2)*sin(phi) + covectorHalfBarLengthFromEndpoint(p).x) / 2,
  141. (covectorEndpoint(p).y-(bl/2)*cos(phi) + covectorHalfBarLengthFromEndpoint(p).y) / 2
  142. )--( covectorEndpoint(p) )
  143. );
  144. }
  145.  
  146. path covector(pair p) {
  147. return covectorStartpoint(p)--covectorEndpoint(p);
  148. }
  149.  
  150. real covectorLength(pair p) {
  151. return sqrt(omegax(p.x, p.y)^2+omegay(p.x, p.y)^2);
  152. }
  153.  
  154. // covector is made of
  155. // - bar at start point
  156. // - bar at end point
  157. // - arrow at end point.
  158. // The bars are like short segments from level curves showing increase of function value by 1.
  159. // If the bars are close to each other, the function is steep here.
  160. // If tha bars are far from each other, the function changes slowly.
  161. path covectorStartbar(pair p) {
  162. // Angle of covector with x-axis
  163. real phi=covectorAngleX(p);
  164. // draw straight line between start point and end point of the bar
  165. return ( (p.x-(bl/2)*sin(phi),p.y+(bl/2)*cos(phi))--(p.x+(bl/2)*sin(phi),p.y-(bl/2)*cos(phi)) );
  166. }
  167.  
  168. path covectorEndbar(pair p) {
  169. // Angle of covector with x-axis
  170. real phi=covectorAngleX(p);
  171. // draw straight line between start point and end point of the bar
  172. return ( (covectorEndpoint(p).x-(bl/2)*sin(phi),covectorEndpoint(p).y+(bl/2)*cos(phi))--(covectorEndpoint(p).x+(bl/2)*sin(phi),covectorEndpoint(p).y-(bl/2)*cos(phi)) );
  173. }
  174.  
  175. // 1-form is a set of covectors defined for any point in the plane
  176. // it is similar to a vectorfield.
  177. //
  178. // We follow a suggestion by Misner, Thorne, Wheeler: Gravity.
  179. // They do not draw a straight line between start and end point.
  180. // Instead they draw two bars and a little arrow at the end point.
  181. //
  182. // We evaluate the covectors on a grid
  183. pen[] couleurs = {blue,red,green,black,orange};
  184. int n = couleurs.length;
  185. for(int ix=-imax; ix<=imax; ix=ix+igridsize) {
  186. for (int iy=-imax; iy<=imax; iy=iy+igridsize) {
  187. if (ix != 0 || iy != 0) {
  188. pen coul = couleurs[ix%n];
  189. pair point=(ix,iy);
  190. dot(point,3bp+coul);
  191. draw(covectorStartbar(point),coul);
  192. draw(covectorEndbar(point),coul);
  193. draw(covectorEndpoint(point),coul);
  194. // test
  195. // draw(covectorHalfBarLengthFromEndpoint(point),green);
  196. draw(arrowLeftpart(point),coul);
  197. draw(arrowRightpart(point),coul);
  198. // Debug (*)
  199. // if (point == DebugPoint) {
  200. // write(point, covectorHalfBarLengthFromEndpoint(point));
  201. // }
  202. // Debug (+)
  203. // draw(covector(point));
  204. }
  205. }
  206. }
  207.  
Index des fonctions - Exemple de lien donnant le résultat d'une recherche sur les mots 'arc' et 'triple' : http://asy.marris.fr/indexasy/?filtre=arc triple
Mes configurations (le 24/02/21) :
PC n°1 :Windows 10 - Asymptote(2.82)+MikTeX2.9 - Editeurs : Notepad++, TeXworks, Visual Studio Code.
PC n°2 : Ubuntu 20.04LTS - Asymptote(2.67-?? git) + TexLive2020
Mon serveur : Debian Stretch- Asymptote(2.68-16 git) + TexLive2018
Merci de préciser la votre !

Avatar du membre
GM
Administrateur du site
Administrateur du site
Messages : 1512
Enregistré le : dim. 7 mars 2010, 14:50

Re: Arrow3

Message non lu par GM » sam. 15 mai 2021, 23:47

J'ai amélioré mes couleurs.

Je m'étonne que le code soit aussi long donc j'essaie de comprendre le cahier des charges, sans me laisser influencer par la façon dont le code est proposé.
Je n'ai pas le temps de décortiquer ce qui est proposé et je n'ai d'ailleurs pas le temps de programmer actuellement mais dans l'éventuelle perspective d'une version personnelle du même dessin, je me pose des questions :

La longueur d'une flèche dépend uniquement des coordonnées du point où elle est tracée ?
L'orientation d'une flèche dépend uniquement des coordonnées du point où elle est tracée ?
Autrement dit, est-ce que le covecteur ne dépend que des coordonnées du point où il est tracé ?
Index des fonctions - Exemple de lien donnant le résultat d'une recherche sur les mots 'arc' et 'triple' : http://asy.marris.fr/indexasy/?filtre=arc triple
Mes configurations (le 24/02/21) :
PC n°1 :Windows 10 - Asymptote(2.82)+MikTeX2.9 - Editeurs : Notepad++, TeXworks, Visual Studio Code.
PC n°2 : Ubuntu 20.04LTS - Asymptote(2.67-?? git) + TexLive2020
Mon serveur : Debian Stretch- Asymptote(2.68-16 git) + TexLive2018
Merci de préciser la votre !

Avatar du membre
GM
Administrateur du site
Administrateur du site
Messages : 1512
Enregistré le : dim. 7 mars 2010, 14:50

Re: Arrow3

Message non lu par GM » dim. 16 mai 2021, 01:56

Pour la figure ci-dessus, j'aurais bricolé quelque chose comme cela, avec des transformations :

Figure asymptote 3a9e7199d0970b98684954b92ddebc33
*** Pour masquer/découvrir le code Asymptote qui a permis de créer la figure, il faut cliquer dessus. ;-) ***

CODE ASYMPTOTE de la figure ci-dessus : Tout sélectionner
  1. import graph;
  2. size(400);
  3.  
  4. real gridsize=1;
  5. int igridsize=1;
  6. real max=2;
  7. int imax=2;
  8. pen[] couleurs = {blue,red,green,black,orange};
  9. int n = couleurs.length;
  10. path[] covector(pair p, real bl=gridsize*0.15) {
  11. path tr = (0,bl/2)--(0,-bl/2), // trait que je vais placer aux 2 extrémités
  12. po = (bl/2,bl/2)--(0,0)--(bl/2,-bl/2); // pointe de flèche
  13. transform t1 = scale(1/(abs(p))^2),
  14. t2 = shift(p)*rotate(-90);
  15. pair A=p, B=shift(p)*rotate(90)*t1*p; // extrémités de la flèche
  16. // Je retourne un array de 3 path formant la flèche.
  17. return new path[] {t2*rotate(degrees(p))*tr, // trait 1 au point p
  18. shift(B-A)*t2*rotate(degrees(p))*tr, // trait 2
  19. shift(B-A)*t2*rotate(degrees(p))*po // pointe 2
  20. };
  21. }
  22.  
  23. xaxis("$u$", xmin=-max*1.3,xmax=max*1.3,EndArrow);
  24. yaxis("$v$", ymin=-max*1.3,ymax=max*1.3,EndArrow);
  25.  
  26. for(int ix=-imax; ix<=imax; ix=ix+igridsize) {
  27. for (int iy=-imax; iy<=imax; iy=iy+igridsize) {
  28. if (ix != 0 || iy != 0) {
  29. pen coul = couleurs[ix%n];
  30. pair pt=(ix,iy);
  31. dot(pt,3bp+coul);
  32. draw(covector(pt),coul);
  33. }
  34. }
  35. }
  36.  


ou s'il faut accéder aux attributs d'un covecteur (points, longueur, angle, ...), traiter le covecteur comme un objet (avec : STRUCT , dans l'esprit de ce qu'à fait Philippe Ivaldi dans l'extension geometry.)
Index des fonctions - Exemple de lien donnant le résultat d'une recherche sur les mots 'arc' et 'triple' : http://asy.marris.fr/indexasy/?filtre=arc triple
Mes configurations (le 24/02/21) :
PC n°1 :Windows 10 - Asymptote(2.82)+MikTeX2.9 - Editeurs : Notepad++, TeXworks, Visual Studio Code.
PC n°2 : Ubuntu 20.04LTS - Asymptote(2.67-?? git) + TexLive2020
Mon serveur : Debian Stretch- Asymptote(2.68-16 git) + TexLive2018
Merci de préciser la votre !

Répondre