Created
May 21, 2022 17:04
-
-
Save thu0x31/ade921c774981b06cd3a537e990b0f21 to your computer and use it in GitHub Desktop.
innerTangents 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
| function vector[] innerTangents(vector circle1Pos, circle2Pos; | |
| float circle1Radius, circle2Radius) { | |
| float hypotenuse = distance(circle1Pos, circle2Pos); | |
| float shortEdgeLen = circle1Radius + circle2Radius; | |
| float rad = atan2(circle2Pos.z - circle1Pos.z, circle2Pos.x - circle1Pos.x) | |
| + asin(shortEdgeLen/hypotenuse) - PI/2; | |
| vector circle1InnerTangent1 = set( | |
| circle1Pos.x + circle1Radius * cos(rad), | |
| circle1Pos.y, | |
| circle1Pos.z + circle1Radius * sin(rad) | |
| ); | |
| vector circle2InnerTangent1 = set( | |
| circle2Pos.x + circle2Radius * cos(rad + PI), | |
| circle2Pos.y, | |
| circle2Pos.z + circle2Radius * sin(rad + PI) | |
| ); | |
| float oppositeRad = atan2(circle2Pos.z - circle1Pos.z, circle2Pos.x - circle1Pos.x) | |
| - asin(shortEdgeLen/hypotenuse) + PI/2; | |
| vector circle1InnerTangent2 = set( | |
| circle1Pos.x + circle1Radius * cos(oppositeRad), | |
| circle1Pos.y, | |
| circle1Pos.z + circle1Radius * sin(oppositeRad) | |
| ); | |
| vector circle2InnerTangent2 = set( | |
| circle2Pos.x + circle2Radius * cos(oppositeRad + PI), | |
| circle2Pos.y, | |
| circle2Pos.z + circle2Radius * sin(oppositeRad + PI) | |
| ); | |
| return array(circle1InnerTangent1, circle1InnerTangent2, circle2InnerTangent1, circle2InnerTangent2); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment