メニュー 閉じる

159. p5.jsでいろんな正多面体を描画して動かしてみる01

こちらを参考にさせていただき、正多面体を描画してみました。

https://www.velvet-number.com/p5_test/test115/

正四面体、正六面体、正八面体、正十二面体、正二十面体を描画できるようにしています。
各多面体の頂点は以下のような感じです。

// 正四面体:4頂点
point_p04[0] = new p5.Vector (-sqrt (3.0) * pr, -sqrt (3.0) * pr, -sqrt (3.0) * pr);
point_p04[1] = new p5.Vector (-sqrt (3.0) * pr,  sqrt (3.0) * pr,  sqrt (3.0) * pr);
point_p04[2] = new p5.Vector ( sqrt (3.0) * pr, -sqrt (3.0) * pr,  sqrt (3.0) * pr);
point_p04[3] = new p5.Vector ( sqrt (3.0) * pr,  sqrt (3.0) * pr, -sqrt (3.0) * pr);

// 正六面体:8頂点
point_p06[0] = new p5.Vector (-pr, -pr, -pr);
point_p06[1] = new p5.Vector (-pr, -pr,  pr);
point_p06[2] = new p5.Vector (-pr,  pr, -pr);
point_p06[3] = new p5.Vector (-pr,  pr,  pr);
point_p06[4] = new p5.Vector ( pr, -pr, -pr);
point_p06[5] = new p5.Vector ( pr, -pr,  pr);
point_p06[6] = new p5.Vector ( pr,  pr, -pr);
point_p06[7] = new p5.Vector ( pr,  pr,  pr);

// 正八面体:6頂点
point_p08[0] = new p5.Vector (-sqrt (3.0) * pr,              0.0,              0.0);
point_p08[1] = new p5.Vector (             0.0, -sqrt (3.0) * pr,              0.0);
point_p08[2] = new p5.Vector (             0.0,              0.0, -sqrt (3.0) * pr);
point_p08[3] = new p5.Vector ( sqrt (3.0) * pr,              0.0,              0.0);
point_p08[4] = new p5.Vector (             0.0,  sqrt (3.0) * pr,              0.0);
point_p08[5] = new p5.Vector (             0.0,              0.0,  sqrt (3.0) * pr);


// 正十二面体:20頂点(係数)
k12 = sqrt (10 / (25 + 11 * sqrt (5.0)));
a12 = (1.0 + sqrt (5.0)) / 2.0;
point_p12[0]  = new p5.Vector (                    0.0,               -k12 * pr, -k12 * (a12 * a12) * pr);
point_p12[1]  = new p5.Vector (                    0.0,                k12 * pr, -k12 * (a12 * a12) * pr);
point_p12[2]  = new p5.Vector (                    0.0,               -k12 * pr,  k12 * (a12 * a12) * pr);
point_p12[3]  = new p5.Vector (                    0.0,                k12 * pr,  k12 * (a12 * a12) * pr);
point_p12[4]  = new p5.Vector (              -k12 * pr, -k12 * (a12 * a12) * pr,                     0.0);
point_p12[5]  = new p5.Vector (               k12 * pr, -k12 * (a12 * a12) * pr,                     0.0);
point_p12[6]  = new p5.Vector (              -k12 * pr,  k12 * (a12 * a12) * pr,                     0.0);
point_p12[7]  = new p5.Vector (               k12 * pr,  k12 * (a12 * a12) * pr,                     0.0);
point_p12[8]  = new p5.Vector (-k12 * (a12 * a12) * pr,                     0.0,               -k12 * pr);
point_p12[9]  = new p5.Vector (-k12 * (a12 * a12) * pr,                     0.0,                k12 * pr);
point_p12[10] = new p5.Vector ( k12 * (a12 * a12) * pr,                     0.0,               -k12 * pr);
point_p12[11] = new p5.Vector ( k12 * (a12 * a12) * pr,                     0.0,                k12 * pr);
point_p12[12] = new p5.Vector (        -k12 * a12 * pr,         -k12 * a12 * pr,         -k12 * a12 * pr);
point_p12[13] = new p5.Vector (        -k12 * a12 * pr,         -k12 * a12 * pr,          k12 * a12 * pr);
point_p12[14] = new p5.Vector (        -k12 * a12 * pr,          k12 * a12 * pr,         -k12 * a12 * pr);
point_p12[15] = new p5.Vector (        -k12 * a12 * pr,          k12 * a12 * pr,          k12 * a12 * pr);
point_p12[16] = new p5.Vector (         k12 * a12 * pr,         -k12 * a12 * pr,         -k12 * a12 * pr);
point_p12[17] = new p5.Vector (         k12 * a12 * pr,         -k12 * a12 * pr,          k12 * a12 * pr);
point_p12[18] = new p5.Vector (         k12 * a12 * pr,          k12 * a12 * pr,         -k12 * a12 * pr);
point_p12[19] = new p5.Vector (         k12 * a12 * pr,          k12 * a12 * pr,          k12 * a12 * pr);

// 正二十面体:12頂点(係数)
k20 = 6.0 / (3.0 * sqrt (3.0) + sqrt (15.0));
a20 = (1.0 + sqrt (5.0)) / 2.0;
point_p20[0]  = new p5.Vector (            0.0,       -k20 * pr, -k20 * a20 * pr);
point_p20[1]  = new p5.Vector (            0.0,        k20 * pr, -k20 * a20 * pr);
point_p20[2]  = new p5.Vector (            0.0,       -k20 * pr,  k20 * a20 * pr);
point_p20[3]  = new p5.Vector (            0.0,        k20 * pr,  k20 * a20 * pr);
point_p20[4]  = new p5.Vector (-k20 * a20 * pr,             0.0,       -k20 * pr);
point_p20[5]  = new p5.Vector (-k20 * a20 * pr,             0.0,        k20 * pr);
point_p20[6]  = new p5.Vector ( k20 * a20 * pr,             0.0,       -k20 * pr);
point_p20[7]  = new p5.Vector ( k20 * a20 * pr,             0.0,        k20 * pr);
point_p20[8]  = new p5.Vector (      -k20 * pr, -k20 * a20 * pr,             0.0);
point_p20[9]  = new p5.Vector (       k20 * pr, -k20 * a20 * pr,             0.0);
point_p20[10] = new p5.Vector (      -k20 * pr,  k20 * a20 * pr,             0.0);
point_p20[11] = new p5.Vector (       k20 * pr,  k20 * a20 * pr,             0.0);

Posted in javascript , p5.js , processing