I have a triangle that intersects with the sphere
How to count triangle area, which is in sphere?
If you have solution for polygon too, it's awesome.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI have a triangle that intersects with the sphere
How to count triangle area, which is in sphere?
If you have solution for polygon too, it's awesome.
Let's take
ball = Ball[];
triangle = Triangle[{{0, 0, 0}, {2, 0, 0}, {2, 3, 1}}];
Graphics3D[{ball, triangle}, Axes -> True]
Then
reg = RegionIntersection[ball, triangle];
DiscretizeRegion[reg]
RegionDimension[reg]
2
RegionMeasure[reg]
$\frac{1}{4} \left(\pi -2 \sin ^{-1}\left(\sqrt{\frac{2}{7}}\right)\right)$
N@%
0.503427
Similarly for Polygon
s. The coordinates of neither the ball
, nor the triangle
(nor Polygon
) need to be integers - all work just as well when they are real numbers (the RegionMeasure
is a real number too).
make a 2d projection to the plane of the triangle and use RegionIntersection
.
triangle = Triangle[{{0, 0, 0}, {2, 0, 0}, {2, 3, 1}}];
ball = Ball[{1, 0, 0}, 1];
spherecenter = ball[[1]];
sphererad = ball[[2]];
pts = First@(List @@ triangle);
v1 = Normalize[pts[[2]] - pts[[1]]];
n = Normalize[Cross[v1, pts[[3]] - pts[[1]]]];
v2 = Cross[n, v1];
tri2d = Triangle[{v1, v2}.# & /@ (# - pts[[1]] & /@ pts)];
cc = {v1, v2}.(spherecenter - pts[[1]]);
d = sphererad^2 - ((spherecenter - pts[[1]]).n)^2;
r2d = If[d > 0, Sqrt[d], 0];
Area@RegionIntersection[tri2d, Disk[cc, r2d]]
1/28 (4 Sqrt[10] + 7 [Pi] + 14 ArcSin[3/7])
( notice I moved the ball center compared to corey979's example to make it a little more interesting )