- 积分
- 12
- 注册时间
- 2008-7-11
- 仿真币
-
- 最后登录
- 1970-1-1
|
那就来个好玩儿的吧,前两天随手写的。- ApplyClippingFunction =
- Function[{x, y, z},
- And @@ (Function[o,
- Plus @@ ({x, y, z} o[[1]]) < o[[2]]] /@ #)] &;
- ApplyPlottingRange = {{x, #[[1, 1]] + #[[2]], #[[1, 1]] - #[[
- 2]]}, {y, #[[1, 2]] + #[[2]], #[[1, 2]] - #[[2]]}, {z, #[[1,
- 3]] + #[[2]], #[[1, 3]] - #[[2]]}} &;
- DrawingParameters := {Mesh -> False, Boxed -> False, Axes -> False,
- ContourStyle ->
- Directive[ColorData["StarryNightColors"][RandomReal[{0.7, 1}]],
- Opacity[0.7], Specularity[White, 30]]} &;
- DrawSphere = ContourPlot3D[
- Plus @@ (({x, y, z} - First@#1)^2) == Last@#1^2,
- Evaluate[Sequence @@ ApplyPlottingRange[#1]],
- Evaluate[Sequence @@ DrawingParameters],
- RegionFunction -> ApplyClippingFunction[#2]
- ] &;
复制代码
- DistanceSquare =
- Plus @@ ((#2[[1]] - #1[[1]])^2) &(*Square of center distance*);
- Ratio = (#1[[2]]^2 + DistanceSquare[#1, #2] - #2[[2]]^2)/(2
- DistanceSquare[#1, #2]) &;
- ClipPlane =
- If[#1 == #2, {{0, 0, 0},
- Infinity}, {#2[[1]] - #1[[
- 1]], (#2[[1]] - #1[[1]]).(#1[[1]] + (#2[[1]] - #1[[1]])*
- Ratio[#1, #2])}] &;
- GetPlaneListOfSingleSphere[sphereList_List, i_Integer] :=
- ClipPlane[sphereList[[i]], #] & /@ Drop[sphereList, {i}];
- DrawIthClippedSphere[sphereList_List, i_Integer] :=
- DrawSphere[sphereList[[i]],
- GetPlaneListOfSingleSphere[sphereList, i]];
- DrawAllSpheres[sphereList_List] :=
- DrawIthClippedSphere[sphereList, #] & /@ Range[Length[sphereList]];
- GenerateSpheres[centerRange_, radiusRangeL_, radiusRangeR_,
- pointNumber_] :=
- Transpose@{RandomReal[{-centerRange, centerRange}, {pointNumber, 3}],
- RandomReal[{radiusRangeL, radiusRangeR}, pointNumber]}
- Show[{DrawAllSpheres[A = GenerateSpheres[5, 3, 6, 8]]}, Boxed -> True,
- PlotRange -> 10]
复制代码 |
评分
-
1
查看全部评分
-
|