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.

Revisions

  1. thu0x31 renamed this gist May 23, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. thu0x31 created this gist May 23, 2022.
    19 changes: 19 additions & 0 deletions contactTriangle.vex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // 接線 : 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);
    }