Skip to content

Instantly share code, notes, and snippets.

@thu0x31
Last active May 24, 2022 22:50
Show Gist options
  • Save thu0x31/9a6ddb0a453a8dfc25c1694b63717f08 to your computer and use it in GitHub Desktop.
Save thu0x31/9a6ddb0a453a8dfc25c1694b63717f08 to your computer and use it in GitHub Desktop.
contactTriangle
// 接線 : https://examist.jp/mathematics/plane-figure/tyouten-setten/
function void drawContactTriangle(vector pA, pB, pC) {
float lenA = distance(pB, pC);
float lenB = distance(pA, pC);
float lenC = distance(pA, pB);
float x = (lenA + (-lenB - lenC)) / -2;
vector contactPos0 = pA + normalize(pC - pA) * x;
int contactPtN0 = addpoint(0, contactPos0);
setpointgroup(0, "contactPoints", contactPtN0, 1);
vector contactPos1 = pA + normalize(pB - pA) * x;
int contactPtN1 = addpoint(0, contactPos1);
setpointgroup(0, "contactPoints", contactPtN1, 1);
vector contactPos2 = pC + normalize(pB - pC) * (lenB - x);
int contactPtN2 = addpoint(0, contactPos2);
setpointgroup(0, "contactPoints", contactPtN2, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment