找回密码
 注册
Simdroid-非首页
查看: 173|回复: 3

[图形图像] Sphere clipping

[复制链接]
发表于 2010-12-15 06:17:13 | 显示全部楼层 |阅读模式 来自 美国
那就来个好玩儿的吧,前两天随手写的。
  1. ApplyClippingFunction =
  2.   Function[{x, y, z},
  3.     And @@ (Function[o,
  4.         Plus @@ ({x, y, z} o[[1]]) < o[[2]]] /@ #)] &;
  5. ApplyPlottingRange = {{x, #[[1, 1]] + #[[2]], #[[1, 1]] - #[[
  6.        2]]}, {y, #[[1, 2]] + #[[2]], #[[1, 2]] - #[[2]]}, {z, #[[1,
  7.        3]] + #[[2]], #[[1, 3]] - #[[2]]}} &;
  8. DrawingParameters := {Mesh -> False, Boxed -> False, Axes -> False,
  9.     ContourStyle ->
  10.      Directive[ColorData["StarryNightColors"][RandomReal[{0.7, 1}]],
  11.       Opacity[0.7], Specularity[White, 30]]} &;

  12. DrawSphere = ContourPlot3D[
  13.     Plus @@ (({x, y, z} - First@#1)^2) == Last@#1^2,
  14.     Evaluate[Sequence @@ ApplyPlottingRange[#1]],
  15.     Evaluate[Sequence @@ DrawingParameters],
  16.     RegionFunction -> ApplyClippingFunction[#2]
  17.     ] &;
复制代码


  1. DistanceSquare =
  2.   Plus @@ ((#2[[1]] - #1[[1]])^2) &(*Square of center distance*);
  3. Ratio = (#1[[2]]^2 + DistanceSquare[#1, #2] - #2[[2]]^2)/(2
  4.       DistanceSquare[#1, #2]) &;
  5. ClipPlane =
  6.   If[#1 == #2, {{0, 0, 0},
  7.      Infinity}, {#2[[1]] - #1[[
  8.        1]], (#2[[1]] - #1[[1]]).(#1[[1]] + (#2[[1]] - #1[[1]])*
  9.          Ratio[#1, #2])}] &;

  10. GetPlaneListOfSingleSphere[sphereList_List, i_Integer] :=
  11.   ClipPlane[sphereList[[i]], #] & /@ Drop[sphereList, {i}];
  12. DrawIthClippedSphere[sphereList_List, i_Integer] :=  
  13.   DrawSphere[sphereList[[i]],
  14.    GetPlaneListOfSingleSphere[sphereList, i]];
  15. DrawAllSpheres[sphereList_List] :=
  16.   DrawIthClippedSphere[sphereList, #] & /@ Range[Length[sphereList]];

  17. GenerateSpheres[centerRange_, radiusRangeL_, radiusRangeR_,
  18.   pointNumber_] :=
  19. Transpose@{RandomReal[{-centerRange, centerRange}, {pointNumber, 3}],
  20.     RandomReal[{radiusRangeL, radiusRangeR}, pointNumber]}

  21. Show[{DrawAllSpheres[A = GenerateSpheres[5, 3, 6, 8]]}, Boxed -> True,
  22.   PlotRange -> 10]
复制代码

评分

1

查看全部评分

发表于 2010-12-15 09:16:03 | 显示全部楼层 来自 浙江绍兴
Simdroid开发平台
欣赏了     看不懂  但是还是看了  呵呵  谢谢
回复 不支持

使用道具 举报

发表于 2010-12-17 22:11:19 | 显示全部楼层 来自 上海
最近我对计算几何也非常着迷,它大大超出了我的想象力。
回复 不支持

使用道具 举报

发表于 2010-12-19 16:47:03 | 显示全部楼层 来自 安徽芜湖
呵呵,永远跟不上 tao的 思维啊,太神奇了。
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-19 09:25 , Processed in 0.036090 second(s), 18 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表