フィルターのクリア

Find length of intersection between 2 points and a sphere

1 回表示 (過去 30 日間)
BenL
BenL 2017 年 1 月 25 日
コメント済み: Andrei Bobrov 2017 年 1 月 31 日
I have a sphere and 2 points. The points have (x,y,z) coordinates and the sphere is defined by its centre (0,0,0) and radius R. I am trying to find the length between the 2 points which intersects the sphere. How can I script this out in Matlab?
See below, my objective is Length, L:
  2 件のコメント
Jan
Jan 2017 年 1 月 25 日
Are you looking for a symbolic or numeric solution?
BenL
BenL 2017 年 1 月 25 日
編集済み: BenL 2017 年 1 月 25 日
im actually looking for a symbolic solution, but need a script for this. I will try to code this from the comments provided. Thanks Jan

サインインしてコメントする。

回答 (3 件)

Roger Stafford
Roger Stafford 2017 年 1 月 25 日
Let P1 = [x1,y1,z1], P2 = [x2,y2,z2], and P0 the sphere center.
v = P1-P0-dot(P1-P0,P2-P1)/dot(P2-P1,P2-P1)*(P2-P1);
L = 2*sqrt(R^2-dot(v,v));
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2017 年 1 月 25 日
Hi Roger! +1
Roger Stafford
Roger Stafford 2017 年 1 月 26 日
Thanks Andrei.

サインインしてコメントする。


Torsten
Torsten 2017 年 1 月 25 日
https://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection
The length L is simply abs(d1-d2) where d1, d2 are the two solutions of the quadratic equation ad^2+bd+c=0.
Best wishes
Torsten.

Roger Stafford
Roger Stafford 2017 年 1 月 27 日
Since this problem is in three dimensions, you can also make use of the cross product function to compute L as follows. Again, we have: P1 = [x1,y1,z1], P2 = [x2,y2,z2], and P0 is the center of the sphere of radius R.
u = P2-P1;
v = cross(P0-P1,u);
L = 2*sqrt(R^2-dot(v,v)/dot(u,u));
  3 件のコメント
Roger Stafford
Roger Stafford 2017 年 1 月 28 日
Yes, P0 can be any three-element vector, including [0,0,0], in both of the methods I have described. The essential property that is required is that all three vectors P1, P2, and P0 should be such that the infinite straight line through P1 and P2 will intersect a sphere of radius R about P0. Otherwise, in both methods the final code line would be taking the square root of a negative value, which will yield an imaginary number.
Andrei Bobrov
Andrei Bobrov 2017 年 1 月 31 日
+1

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by