Orientation of a closed path with Asymptote – fig0040

Catégorie : Asymptote, Path Orientation, SurveysPh. Ivaldi @ 0 h 36 min

Figure 0004
(Compiled with Asymptote version 1.84svn-r4619)
    
// Use of the windingnumber works also for CROSSED curves

size(8cm,10cm,false);

import math;

bool counterclockwise(path g)
{
  // Return "true" if "g" is counterclockwise
  // Retounre "true" si "g" est dans le sens contraire des aiguilles d'une montre
  return (windingnumber(g,inside(g)) > 0);
}

path counterclockdirected(path g)
{
  if (counterclockwise(g)) return g; else return reverse(g);
}

guide p=randompath(30)..cycle;
draw(counterclockdirected(reverse(p)),Arrow(10bp,Relative(0.025)), BeginBar);
draw(counterclockdirected(p),Arrow(10bp,FillDraw(red),Relative(.05)), BeginBar);


Orientation of a closed path with Asymptote – fig0030

Catégorie : Asymptote, Path Orientation, SurveysPh. Ivaldi @ 23 h 36 min

Figure 0003
(Compiled with Asymptote version 1.84svn-r4619)
    
// Use of the native windingnumber Asymptote routine
// this is the most fast and robust.
// Utilisation du nombre d'enroulement avec la routine native windingnumber d'Asymptote
// c'est plus rapide et plus robuste.
/*
Explanations are here: http://mathworld.wolfram.com/ContourWindingNumber.html
*/

size(6cm,0, false);
bool counterclockwise(path g, pair z) {return windingnumber(g,z) > 0;}

path counterclockdirected(path g,pair z)
{
  if (counterclockwise(g,z)) return g; else return reverse(g);
}

pair z=(1,0);
dot(z);
path p=(0,0){N}..(4,0){N}..cycle;
draw(counterclockdirected(reverse(p),z),Arrow(Relative(.1)), BeginBar);
draw(counterclockdirected(p,z),Arrow(position=Relative(.2),FillDraw(red)), BeginBar);

pair z=(3,-2);
dot(z);
path p=(4,-2){N}..(0,-2){N}..cycle;
draw(counterclockdirected(reverse(p),z),Arrow(Relative(.1)), BeginBar);
draw(counterclockdirected(p,z),Arrow(position=Relative(.2),FillDraw(red)), BeginBar);

pair z=(1,-4.5);
dot(z);
path p=yscale(.75)*((0,-6){N}..(2,-6){S}..(0,-6){N}..(4,-6){S}..cycle);
draw(counterclockdirected(reverse(p),z),Arrow(Relative(.1)), BeginBar);
draw(counterclockdirected(p,z),Arrow(position=Relative(.2),FillDraw(red)), BeginBar);

pair z=(3,-8);
dot(z);
path p=shift((0,-3.5))*p;
draw(counterclockdirected(reverse(p),z),Arrow(Relative(.1)), BeginBar);
draw(counterclockdirected(p,z),Arrow(position=Relative(.2),FillDraw(red)), BeginBar);


Orientation of a closed path with Asymptote – fig0020

Catégorie : Asymptote, Path Orientation, SurveysPh. Ivaldi @ 22 h 36 min

Figure 0002
(Compiled with Asymptote version 1.84svn-r4619)
    
size(6cm);
bool counterclockwise(path g, int n=10^3)
{
  // Return "true" if "g" (SIMPLE CURVE i.e. NON CROSSED) is counterclockwise
  // Retounre "true" si "g" (NON CROISÉ) est dans le sens contraire des aiguilles d'une montre
  if (!cyclic(g) || length(g)==0) abort("The function 'clocksize' needs cyclic path.");
  pair [] pt;
  real l=length(g),
    step=1/n,
    t=0,
    sa=0;
  do {
    sa +=point(g,t).x * (point(g,t+step).y - point(g,t-step).y);
    t+=step;
  } while (t<l);
  return (sgn(sa) > 0);
}

path counterclockdirected(path g,int n=10^3)
{
  // Return "g" (SIMPLE CURVE i.e. NON CROSSED) counterclockwise
  // Retourne "g" (NON CROISÉ) dans le sens des aiguilles d'une montre
  if (counterclockwise(g,n)) return g; else return reverse(g);
}

path p=unitcircle;
draw(counterclockdirected(reverse(p)),
     Arrow(Relative(.1)), BeginBar);
draw(counterclockdirected(p),
     Arrow(position=Relative(.2),FillDraw(red)), BeginBar);


Orientation of a closed path with Asymptote – fig0010

Catégorie : Asymptote, Path Orientation, SurveysPh. Ivaldi @ 21 h 36 min

Figure 0001
(Compiled with Asymptote version 1.84svn-r4619)
    
/*
About the used algorithms look at:
http://cgafaq.info/wiki/Simple_Polygon_Orientation
*/

size(8cm, false);

real signedArea(pair [] pt)
{
  // Return the signed area of a simple (NON CROSSED) polygon of vertex "pt"
  // Retourne l'aire algébrique d'un polygone NON CROIÉ
  pair [] pt_= copy(pt);
  real n=pt.length,
    sa=0;
  pt_.push(pt_[0]);
  pt_.push(pt_[1]);
  
  for (int i=1; i<=n; ++i) sa +=pt_[i].x * (pt_[i+1].y - pt_[i-1].y);
  return sa/2;
}

bool counterclockwise(pair [] pt)
{
  // Return "true" if the polygon (SIMPLE CURVE i.e. NON CROSSED)
  // of vertex "pt" is counterclockwise
  // Retourne "true" si le polygone (NON CROISÉ) de sommets "pt"
  // est dans le sens des aiguilles d'une montre
  return (signedArea(pt) > 0);
}

pair [] reverse(pair [] pt)
{
  pair [] pt_=copy(pt);
  int begin=0, end=pt.length-1;
  while (begin<end)
    {
      pair temp=pt_[begin];
      pt_[begin]=pt_[end];
      pt_[end]=temp;
      ++begin; --end;
    }
  return pt_;
}

pair [] counterclockdirected(pair [] pt)
{
  if (counterclockwise(pt)) return pt; else return reverse(pt);
}

path polygon(pair [] pt)
{
  int l=pt.length;
  guide opath;
  for (int i=0; i<l; ++i)
    {
      opath = opath--pt[i];
    }
  return opath;
}

pair [] pg = {(0,0), (1,0), (1,1), (2,2), (-1,1)};
draw(polygon(pg)--cycle,
     Arrow(Relative(.1)), BeginBar);
draw(polygon(counterclockdirected(reverse(pg)))--cycle,
     Arrow(position=Relative(.2), FillDraw(red)), BeginBar);


L-System with Asymptote – fig0240

Catégorie : Asymptote, L-SystemPh. Ivaldi @ 18 h 40 min

Figure 0024
(Compiled with Asymptote version 1.84svn-r4619)
    
/*Inspirtaion*/
import Lsystem;
size(10cm,10cm);
settings.outformat="pdf"; // for opacity

string[][] rules=new string[][]{{"F", "FF"},{"X", "F-[[X]+X]+F[+FX]-X"}};
Lsystem plant=Lsystem("X", rules, La=22.5, Lai=90);
plant.iterate(8);
path[] g=plant.paths();

tree g=plant.tree();

for (int i:g.keys) {
  if((g[i].depth <= 2 )) draw(g[i].g, yellow);
}

for (int i:g.keys) {
  if((g[i].depth > 2 ) && (g[i].depth <= 10 )) draw(g[i].g, green+opacity(0.5));
}

for (int i:g.keys) {
  if((g[i].depth > 11)) draw(g[i].g, brown+opacity(0.3));
}

shipout(bbox(Fill(paleyellow)));

Mots-clefs : ,


L-System with Asymptote – fig0230

Catégorie : Asymptote, L-SystemPh. Ivaldi @ 17 h 40 min

Figure 0023
(Compiled with Asymptote version 1.86svn-r4626)
    
/*Inspirtaion*/
import Lsystem;
size(10cm,10cm);
settings.outformat="pdf"; // for opacity

string[][] rules=new string[][]{{"F", "FF-[-F+F+F]+[+F-F-F]"}};
Lsystem plant=Lsystem("F", rules, La=22.5, Lai=90);
plant.iterate(5);
path[] g=plant.paths();

tree g=plant.tree();

for (int i:g.keys) {
  if((g[i].depth == 0)) draw(g[i].g, yellow);
}

for (int i:g.keys) {
  if((g[i].depth > 0 )) draw(g[i].g, green+opacity(0.5));
}

for (int i:g.keys) {
  if((g[i].depth > 15)) draw(g[i].g, brown+opacity(0.3));
}

shipout(bbox(Fill(paleyellow)));

Mots-clefs : ,


L-System with Asymptote – fig0220

Catégorie : Asymptote, L-SystemPh. Ivaldi @ 16 h 40 min

Figure 0022
(Compiled with Asymptote version 1.84svn-r4619)
    
/* Double pavage de Penrose
  Source */
import Lsystem;
size(8cm,0);

string[][] rules={
  {"W", "YF++ZF----XF[-YF----WF]++"},
  {"X", "+YF--ZF[---WF--XF]+"},
  {"Y", "-WF++XF[+++YF++ZF]-"},
  {"Z", "--YF++++WF[+ZF++++XF]--XF"},
  {"F", ""}
};

Lsystem Penrose=Lsystem("[X][Y]++[X][Y]++[X][Y]++[X][Y]++[X][Y]",rules,La=36);

Penrose.iterate(3);
draw(Penrose.paths(), linewidth(bp));

shipout(bbox(2mm, FillDraw(lightyellow,linewidth(1mm))));

Mots-clefs : ,


L-System with Asymptote – fig0210

Catégorie : Asymptote, L-SystemPh. Ivaldi @ 15 h 40 min

Figure 0021
(Compiled with Asymptote version 1.84svn-r4619)
    
/* Pavage de Penrose
  Source */
import Lsystem;
size(8cm,0);

string[][] rules={
  {"W", "YF++ZF----XF[-YF----WF]++"},
  {"X", "+YF--ZF[---WF--XF]+"},
  {"Y", "-WF++XF[+++YF++ZF]-"},
  {"Z", "--YF++++WF[+ZF++++XF]--XF"},
  {"F", ""}
};

Lsystem Penrose=Lsystem("++ZF----XF-YF----WF",rules,La=36);

Penrose.iterate(4);
draw(Penrose.paths(), linewidth(bp));

shipout(bbox(2mm, FillDraw(lightyellow,linewidth(1mm))));

Mots-clefs : ,


L-System with Asymptote – fig0200

Catégorie : Asymptote, L-SystemPh. Ivaldi @ 14 h 40 min

Figure 0020
(Compiled with Asymptote version 1.84svn-r4619)
    
/* Pavage P3 de Penrose
  Drawing the Penrose tiling P3 */
import Lsystem;
size(8cm,0);

string[][] rules={
  {"6","8F++9F----7F[-8F----6F]++"},
  {"7","+8F--9F[---6F--7F]+"},
  {"8","-6F++7F[+++8F++9F]-"},
  {"9","--8F++++6F[+9F++++7F]--7F"},
  {"F",""}
};

Lsystem Penrose=Lsystem("[7]++[7]++[7]++[7]++[7]", rules, La=36);
Penrose.iterate(4);
draw(Penrose.paths(), linewidth(bp));

shipout(bbox(2mm, FillDraw(lightyellow,linewidth(1mm))));

Mots-clefs : ,


L-System with Asymptote – fig0190

Catégorie : Asymptote, L-SystemPh. Ivaldi @ 13 h 40 min

Figure 0019
(Compiled with Asymptote version 1.84svn-r4619)
    
/* Source */
import Lsystem;
size(8cm,0);

string[][] rules={
  {"A", "X+X+X+X+X+X+"},
  {"X", "[F+F+F+F[---X-Y]+++++F++++++++F-F-F-F]"},
  {"Y", "[F+F+F+F[---Y]+++++F++++++++F-F-F-F]"}
};

Lsystem spiral=Lsystem("AAAA",rules,La=15);

spiral.iterate(6);
draw(spiral.paths(), 0.9*green);

shipout(bbox(2mm, Fill(black)));

Mots-clefs : ,