Skip to content

Instantly share code, notes, and snippets.

@thu0x31
Last active May 24, 2022 22:50
Show Gist options
  • Save thu0x31/25d72b5ee5fd429b911c997ac930ce4c to your computer and use it in GitHub Desktop.
Save thu0x31/25d72b5ee5fd429b911c997ac930ce4c to your computer and use it in GitHub Desktop.
intersectionTwoCicles vex
// 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
);
}
// 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