Last active
May 24, 2022 22:50
-
-
Save thu0x31/25d72b5ee5fd429b911c997ac930ce4c to your computer and use it in GitHub Desktop.
intersectionTwoCicles 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
// http://paulbourke.net/geometry/circlesphere/ Intersection of two circles | |
function vector intersectionTwoCiclesLeft(vector p0, p1; float radius0, radius1) { | |
float d = distance(p0, p1); | |
float a = (radius0 * radius0 - radius1 * radius1 + d * d) / (2*d); | |
float h = sqrt(radius0 * radius0 - a * a); | |
vector p2 = p0 + a * (p1 - p0) / d; | |
// xz | |
return set( | |
p2.x - h*(p1.z - p0.z)/d, | |
p2.y, | |
p2.z + h*(p1.x - p0.x)/d | |
); | |
} |
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
// http://paulbourke.net/geometry/circlesphere/ Intersection of two circles | |
function vector intersectionTwoCiclesRight(vector p0, p1; float radius0, radius1) { | |
float d = distance(p0, p1); | |
float a = (radius0 * radius0 - radius1 * radius1 + d * d) / (2*d); | |
float h = sqrt(radius0 * radius0 - a * a); | |
vector p2 = p0 + a * (p1 - p0) / d; | |
// xz | |
return set( | |
p2.x + h*(p1.z - p0.z)/d, | |
p2.y, | |
p2.z - h*(p1.x - p0.x)/d | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment