What is the easiest way to find a cyl <-> cyl intersection?
2 次查看(过去 30 天)
显示 更早的评论
Hello, thanks for looking at this,
I've been working on this problem for awhile, basically I want to find the fastest and most accurate way to find the intersection (if one exists) between two cylinders.
I've been looking at doing this using barycentric coordinates, and I can get it working quickly and efficiently using rays. When it comes to 3D, though, the mathematical formulation I have begins to slow down rapidly (~3 seconds for ~100 segments). Is there a faster way to do this, perhaps just using geometry (NURBS perhaps)?
2 个评论
Amit
2013-12-31
编辑:Amit
2013-12-31
Does the cylinders have finite length? In case two cylinders intersect, there can be 2, 4 ,8 or infinte intersection point (infinite in case where two cylinders touch each other). If you are interested in only one intersection point (which verifies the cylinder do intersect), there is a simple approach using fsolve.
回答(1 个)
Amit
2014-1-1
编辑:Amit
2014-1-1
Lets assume both of your cylinders are of radius r1 and r2. You can represent a cylinder in cartesian coordinates (x,y,z) using parameters phi and theta (for more reference see this - http://en.wikipedia.org/wiki/Cylinder_(geometry)#About_an_arbitrary_axis) A ith cylinder can be represented as:
A_i = -x*sin(theta_i)+y*cos(theta_i)*cos(phi_i) + z*cos(theta_1)sin(phi_1)
B_i = -y*sin(phi_1) + z*cos(phi_1)
and A_i^2 + B_i^2 = ri^2
The point of intersection (x1,y1,z1) will satisfy for both cylinders.
So your function will take ([x y z]) as input (which you wanna solve) and in the function you will compute A_1, B_1, A_2 and B_2 and function output will be
F = (A_1^2+B_1^2-r1^2)^2 + (A_2^2+B_2^2-r2^2)^2 % This is what will be zero if condition satifies
You can easily solve this using fsolve. Hope this helps.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!