Skip to content

Instantly share code, notes, and snippets.

@kogcyc
Last active October 15, 2019 17:40
Show Gist options
  • Save kogcyc/69061bd2b39f7fc46873597e8ebb1023 to your computer and use it in GitHub Desktop.
Save kogcyc/69061bd2b39f7fc46873597e8ebb1023 to your computer and use it in GitHub Desktop.
intersection two 2 cylinders - formula
Here is the formula for calculating the intersection points of 2 cylinders where the centerlines of the cylinders intersect.
Definitions:
Brad = Branch Radius
Mrad = Main Radius
TX = the X coord of the intersection
TY = the Y coord of the intersection
TZ = the Z coord of the intersection
deginrad = the Degrees in Radians of the position we are at in the branch's circluar path
ANG = the Angle of the variation of the branch from 90 degrees
First here is the basic easy formula for the intersection of a 90 degree set of cylinders:
TX = Cos(deginrad) * Brad
TY = Sin(deginrad) * Brad
TZ = Sqr(Abs(Mrad ^ 2 - TY ^ 2))
Second is the formula that lets you set the angle of the branch and get the points you need:
TY = Sin(deginrad) * Brad
TZ = Sqr(Abs(Mrad ^ 2 - TY ^ 2))
TX = (Cos(deginrad) * Brad / Cos(Ang)) + (Tan(Ang) * TZ)
Hope this helps.
from math import pi, cos, sin, tan, sqrt, radians
brad = 1.0
mrad = 1.125
ang = radians(0.0)
for degs in range(360):
rads = radians(degs)
tx = round(cos(rads) * brad,3)
ty = round(sin(rads) * brad, 3)
tz = round(sqrt(abs(mrad**2 - ty**2)), 3)
#ty = round(sin(rads) * brad, 3)
#tz = round(sqrt(abs(mrad**2 - ty**2)), 3)
#tx = round((cos(rads) * brad / cos(ang)) + (tan(ang) * tz), 3)
print(str(tx) + ' ' + str(ty) + ' ' + str(tz))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment