gyroidジャイロイド

# gyroid
　数式で定義される立体造形のうち「gyroid」にトライ。
```math
sin(x)cos(y) + sin(y)cos(z) + sin(z)cos(x)=0
```

`z=0`断面を描き、マウス操作で、zの値を変化させる。

立体モデルを出力するのは、大変そうである。
参考動画のように、手動でポリゴンモデリングするか、
陰関数なので、レイトレーシングするか、
断面画像を保存して、変換サイトで、STLなどに変換するか。
いずれにしろ面倒だ。



![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/510257/7472c1f4-e5ca-93ed-7746-884bc94b9d9c.png)

```java
void setup() {
  size(256, 256);
}

void draw() {
  float zz = mouseY;
  float z=zz*2*PI/(float)height;
  color c = 0;

  loadPixels();
  for (int yy=0; yy<height; yy++) {
    for (int xx=0; xx<height; xx++) {
      float x=xx*2*PI/(float)width;
      float y=yy*2*PI/(float)height;
      float ans = sin(x)*cos(y) + sin(y)*cos(z) + sin(z)*cos(x);
      ans = map(ans,-1,1,0,1);
      if(ans<0.3){
        c = color(0);
      }else if(ans<0.7){
        c = color(128);
      }else{
        c = color(255);
      }
      pixels[yy*height+xx] = c;
    }
  }
  updatePixels();
}
```

# シュワルツ P タイプ
```math
cos(x) + cos(y) + cos(z) = 0
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/510257/747b16f9-40c7-e0da-144a-c0b939818e3c.png)

# シュワルツ D タイプ
```math
sin(x)sin(y)sin(z) + sin(x)cos(y)cos(z) + cos(x)sin(y)cos(z) + cos(x)cos(y)sin(z) = 0
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/510257/7803e81c-5364-47ce-26e0-01afca36da9b.png)


# 参考
https://en.wikipedia.org/wiki/Gyroid

https://en.wikipedia.org/wiki/Minimal_surface

https://www.youtube.com/watch?v=bt6wGyALqpY

https://youtu.be/GI2mv5psgTo

https://imagetostl.com/jp


# MELによる自動化
参考動画をたどりながら、MayaのMelを使って、生成する過程。
３点円弧で外枠を作成。
２点円弧で中心部の曲線を作成。
BirailSurfaceで曲面生成。



これからやること。
//結合とマージで、重複頂点削除となめらかな接続にする。
//周辺部以外の頂点調整
//８個へ複製
//結合とマージ

```java:gyroid.mel
//////////////////////
//３点円弧生成
createNode makeThreePointCircularArc -n "obj1";
setAttr obj1.pt1  4 -4 4 ;
setAttr obj1.pt2  2 -4 0 ;
setAttr obj1.pt3  4 -4 -4 ;
setAttr obj1.d 3;
setAttr obj1.s 8;
createNode nurbsCurve -n "curve1";
connectAttr obj1.oc curve1.cr;

createNode makeThreePointCircularArc -n "obj2";
setAttr obj2.pt1 -4 4 4 ;
setAttr obj2.pt2 -2 4 0 ;
setAttr obj2.pt3 -4 4 -4 ;
setAttr obj2.d 3;
setAttr obj2.s 8;
createNode nurbsCurve -n "curve2";
connectAttr obj2.oc curve2.cr;

createNode makeThreePointCircularArc -n "obj3";
setAttr obj3.pt1 4 -4 4 ;
setAttr obj3.pt2 0 -2 4 ;
setAttr obj3.pt3 -4 -4 4 ;
setAttr obj3.d 3;
setAttr obj3.s 8;
createNode nurbsCurve -n "curve3";
connectAttr obj3.oc curve3.cr;

createNode makeThreePointCircularArc -n "obj4";
setAttr obj4.pt1 4 4 -4 ;
setAttr obj4.pt2 0 2 -4 ;
setAttr obj4.pt3 -4 4 -4 ;
setAttr obj4.d 3;
setAttr obj4.s 8;
createNode nurbsCurve -n "curve4";
connectAttr obj4.oc curve4.cr;

createNode makeThreePointCircularArc -n "obj5";
setAttr obj5.pt1 4 4 -4;
setAttr obj5.pt2 4 0 -2;
setAttr obj5.pt3 4 -4 -4;
setAttr obj5.d 3;
setAttr obj5.s 8;
createNode nurbsCurve -n "curve5";
connectAttr obj5.oc curve5.cr;

createNode makeThreePointCircularArc -n "obj6";
setAttr obj6.pt1 -4 4 4;
setAttr obj6.pt2 -4 0 2;
setAttr obj6.pt3 -4 -4 4;
setAttr obj6.d 3;
setAttr obj6.s 8;
createNode nurbsCurve -n "curve6";
connectAttr obj6.oc curve6.cr;
//////////////////////
//２点円弧生成
createNode makeTwoPointCircularArc -n "arc1";
setAttr arc1.pt1 -4 0 2 ;
setAttr arc1.pt2 0 0 0 ;
setAttr arc1.r 5;
setAttr arc1.dv 0 1 0 ;
setAttr arc1.tac 0;
setAttr arc1.d 3;
setAttr arc1.s 8;
createNode nurbsCurve -n "h_arc1";
connectAttr arc1.oc h_arc1.cr ;

createNode makeTwoPointCircularArc -n "arc2";
setAttr arc2.pt1 4 0 -2 ;
setAttr arc2.pt2 0 0 0 ;
setAttr arc2.r 5;
setAttr arc2.dv 0 1 0 ;
setAttr arc2.tac 0;
setAttr arc2.d 3;
setAttr arc2.s 8;
createNode nurbsCurve -n "h_arc2";
connectAttr arc2.oc h_arc2.cr ;

createNode makeTwoPointCircularArc -n "arc3";
setAttr arc3.pt1 2 -4 0 ;
setAttr arc3.pt2 0 0 0 ;
setAttr arc3.r 5;
setAttr arc3.dv 0 0 1 ;
setAttr arc3.tac 0;
setAttr arc3.d 3;
setAttr arc3.s 8;
createNode nurbsCurve -n "h_arc3";
connectAttr arc3.oc h_arc3.cr ;

createNode makeTwoPointCircularArc -n "arc4";
setAttr arc4.pt1 -2 4 0 ;
setAttr arc4.pt2 0 0 0 ;
setAttr arc4.r 5;
setAttr arc4.dv 0 0 1 ;
setAttr arc4.tac 0;
setAttr arc4.d 3;
setAttr arc4.s 8;
createNode nurbsCurve -n "h_arc4";
connectAttr arc4.oc h_arc4.cr ;

createNode makeTwoPointCircularArc -n "arc5";
setAttr arc5.pt1 0 -2 4 ;
setAttr arc5.pt2 0 0 0 ;
setAttr arc5.r 5;
setAttr arc5.dv 1 0 0 ;
setAttr arc5.tac 0;
setAttr arc5.d 3;
setAttr arc5.s 8;
createNode nurbsCurve -n "h_arc5";
connectAttr arc5.oc h_arc5.cr ;

createNode makeTwoPointCircularArc -n "arc6";
setAttr arc6.pt1 0 2 -4 ;
setAttr arc6.pt2 0 0 0 ;
setAttr arc6.r 5;
setAttr arc6.dv 1 0 0 ;
setAttr arc6.tac 0;
setAttr arc6.d 3;
setAttr arc6.s 8;
createNode nurbsCurve -n "h_arc6";
connectAttr arc6.oc h_arc6.cr ;


///////////////////////
//曲面生成
doubleProfileBirailSurface -bl 0.5 -tp2 0 -ch 1 -po 1 -tm 1 -tp1 0 curve10 |curve4 curve12 |curve2 ;
setAttr "nurbsTessellate1.polygonType" 1;
setAttr "nurbsTessellate1.uType" 2;
setAttr "nurbsTessellate1.vType" 2;
setAttr "nurbsTessellate1.uNumber" 5;
setAttr "nurbsTessellate1.vNumber" 5;
doubleProfileBirailSurface -bl 0.5 -tp2 0 -ch 1 -po 1 -tm 1 -tp1 0 curve12 |curve5 curve8 |curve4 ;
setAttr "nurbsTessellate2.polygonType" 1;
setAttr "nurbsTessellate2.uType" 2;
setAttr "nurbsTessellate2.vType" 2;
setAttr "nurbsTessellate2.uNumber" 5;
setAttr "nurbsTessellate2.vNumber" 5;
doubleProfileBirailSurface -bl 0.5 -tp2 0 -ch 1 -po 1 -tm 1 -tp1 0 curve8 |curve1 curve9 |curve5 ;
setAttr "nurbsTessellate3.polygonType" 1;
setAttr "nurbsTessellate3.uType" 2;
setAttr "nurbsTessellate3.vType" 2;
setAttr "nurbsTessellate3.uNumber" 5;
setAttr "nurbsTessellate3.vNumber" 5;
doubleProfileBirailSurface -bl 0.5 -tp2 0 -ch 1 -po 1 -tm 1 -tp1 0 curve9 |curve3 curve11 |curve1 ;
setAttr "nurbsTessellate4.polygonType" 1;
setAttr "nurbsTessellate4.uType" 2;
setAttr "nurbsTessellate4.vType" 2;
setAttr "nurbsTessellate4.uNumber" 5;
setAttr "nurbsTessellate4.vNumber" 5;
doubleProfileBirailSurface -bl 0.5 -tp2 0 -ch 1 -po 1 -tm 1 -tp1 0 curve11 |curve6 curve7 |curve3 ;
setAttr "nurbsTessellate5.polygonType" 1;
setAttr "nurbsTessellate5.uType" 2;
setAttr "nurbsTessellate5.vType" 2;
setAttr "nurbsTessellate5.uNumber" 5;
setAttr "nurbsTessellate5.vNumber" 5;
doubleProfileBirailSurface -bl 0.5 -tp2 0 -ch 1 -po 1 -tm 1 -tp1 0 curve7 |curve2 curve10 |curve6 ;
setAttr "nurbsTessellate6.polygonType" 1;
setAttr "nurbsTessellate6.uType" 2;
setAttr "nurbsTessellate6.vType" 2;
setAttr "nurbsTessellate6.uNumber" 5;
setAttr "nurbsTessellate6.vNumber" 5;

```