Last active
February 1, 2021 12:56
-
-
Save rngtm/12de01b42e5fa67ffe79109eb33585a5 to your computer and use it in GitHub Desktop.
Houdini VEX でメビウスの輪
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tの分割数 | |
int tDiv = 200; | |
// r | |
float rMin = -1; // rの最小値 | |
float rMax = 1; // rの最大値 | |
int rDiv = 2; // rの分割数 | |
// t | |
float tMin = 0; // tの最小値 | |
float tMax = 3 * $PI; // tの最大値 | |
// メビウスの輪の座標計算 | |
vector mobiusPoint(float r; float t){ | |
float x = (r * cos(t) + 2) * cos(2 * t); | |
float y = (r * cos(t) + 2) * sin(2 * t); | |
float z = r * sin(t); | |
return set(x, y, z); | |
} | |
// メビウスの輪の頂点を計算 | |
int mobiusPoints[] = {}; | |
vector vertexColors[] = {}; | |
for (int ti = 0; ti < tDiv; ti++) { | |
float tLerp = float(ti % tDiv) / (tDiv); | |
float t = lerp(tMin, tMax, tLerp); | |
for (int ri = 0; ri < rDiv; ri++) { | |
float rLerp = float(ri) / (rDiv); | |
float r = lerp(rMin, rMax, rLerp); | |
vector p = mobiusPoint(r, t); | |
int pt = addpoint(geoself(), p); | |
append(mobiusPoints, pt); | |
} | |
} | |
// 計算した頂点からメッシュを作成する | |
int ptNum = len(mobiusPoints); | |
int pt = 0; | |
for (int ti = 0; ti < tDiv - 1; ti++) { | |
int points[] = {}; | |
// triangle 1 | |
append(points, mobiusPoints[(pt + 0) % ptNum]); | |
append(points, mobiusPoints[(pt + 1) % ptNum]); | |
append(points, mobiusPoints[(pt + 2) % ptNum]); | |
// triangle 2 | |
append(points, mobiusPoints[(pt + 1) % ptNum]); | |
append(points, mobiusPoints[(pt + 3) % ptNum]); | |
append(points, mobiusPoints[(pt + 2) % ptNum]); | |
addprim(geoself(), "poly", points); | |
pt += 2; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方
結果
メビウスの輪が作成されます。

参考
https://ja.wikipedia.org/wiki/%E3%83%A1%E3%83%93%E3%82%A6%E3%82%B9%E3%81%AE%E5%B8%AF#:~:text=%E3%83%A1%E3%83%93%E3%82%A6%E3%82%B9%E3%81%AE%E5%B8%AF%EF%BC%88%E3%83%A1%E3%83%93%E3%82%A6%E3%82%B9%E3%81%AE,%E3%83%A1%E3%83%BC%E3%83%93%E3%82%A6%E3%82%B9%E3%81%AE%E5%B8%AF%E3%81%A8%E3%82%82%E3%81%84%E3%81%86%E3%80%82