LoginSignup
0
0

More than 5 years have passed since last update.

Tinkercad > Shape Generator > Icosahedron > vert()とtri()で形状定義

Last updated at Posted at 2018-02-28

ブラウザ動作するAutoDeskのTinkercad。

関連

Icosahedron

以下はShape Generatorで使うIcosahedronのmain.js。

main.js
// Convenience Declarations For Dependencies.
// 'Core' Is Configured In Libraries Section.
// Some of these may not be used by this example.
var Conversions = Core.Conversions;
var Debug = Core.Debug;
var Path2D = Core.Path2D;
var Point2D = Core.Point2D;
var Point3D = Core.Point3D;
var Matrix2D = Core.Matrix2D;
var Matrix3D = Core.Matrix3D;
var Mesh3D = Core.Mesh3D;
var Plugin = Core.Plugin;
var Tess = Core.Tess;
var Sketch2D = Core.Sketch2D;
var Solid = Core.Solid;
var Vector2D = Core.Vector2D;
var Vector3D = Core.Vector3D;

// Template Code:
params = [
    {   "id": "radius", 
        "displayName": "Radius",
        "type": "length",
        "rangeMin": 1,
        "rangeMax": 50,
        "default": 20
    }
];

function process(params, data) {    
    var size = params.radius;
    var r = (size / 2) / Math.sin(Math.PI / 5);
    var h = Math.cos(Math.PI / 5) * r;
    var h1 = Math.sqrt(size*size - r*r);
    var hr = h+r;
    var h2 = Math.sqrt(hr*hr - h*h);
    var z2 = (h2 - h1) / 2;
    var z1 = z2 + h1;
    var cx = r * Math.cos(Math.PI / 10);
    var cy = r * Math.sin(Math.PI / 10);

    var mesh = new Mesh3D();
    var verts = [];
    function vert(x, y, z) { verts.push([x, y, z]); }
    function tri(a, b, c) { mesh.triangle(verts[a], verts[b], verts[c]); }

    vert(0, 0, z1);

    vert(0, r, z2);
    vert(cx, cy, z2);
    vert(size/2, -h, z2);
    vert(-size/2, -h, z2);
    vert(-cx, cy, z2);

    vert(0, -r, -z2);
    vert(-cx, -cy, -z2);
    vert(-size/2, h, -z2);
    vert(size/2, h , -z2);
    vert(cx, -cy, -z2);

    vert(0, 0, -z1);

    tri(0, 1, 5);
    tri(0, 2, 1);
    tri(0, 3, 2);
    tri(0, 4, 3);
    tri(0, 5, 4);

    tri(11, 10, 6);
    tri(11, 6, 7);
    tri(11, 7, 8);
    tri(11, 8, 9);
    tri(11, 9, 10);

    tri(1, 2, 9);
    tri(2, 10, 9);
    tri(2, 3, 10);
    tri(3, 6, 10);
    tri(3, 4, 6);
    tri(4, 7, 6);
    tri(4, 5, 7);
    tri(5, 8, 7);
    tri(5, 1, 8);
    tri(1, 9, 8);

    var solid = Solid.make(mesh);

    return solid;
}
  • vert()で頂点座標を定義
    • vertices
  • tri()で頂点のインデックスを3つもつ三角形を定義
    • triangulation

pySphereptsなどの座標データやDelaunay triangulationのデータからvert()とtri()の定義を生成すれば、Tinkercadのオブジェクトとして生成できそうだ。

pySphereptsのデータからは球上の点が生成されるだけなので、面白くはないかもしれない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0