尝试创建一个非常简单的布尔函数,该函数将查找线是否与球体相交.
这似乎不是我想要的,即使问题是相似的: 一条线和一个球体的交点?
我也尝试过列出的算法:
http://www.docstoc.com/docs/7747820/Intersection-of-a-Line-and-a-Sphere
和
http://www.ccs.neu.edu/home/fell/CSU540/programs/RayTracingFormulas.htm
没有真正的运气.
我最近的代码(在Haskell中)看起来像:
data Point = Point { x :: Float, y :: Float, z :: Float} deriving (Eq, Show, Read)
data Sphere = Sphere { center :: Point, radius :: Float } deriving (Eq, Show, Read)
inView :: Point -> Point -> Sphere -> Bool
inView (Point x1 y1 z1) (Point x2 y2 z2) (Sphere (Point x3 y3 z3) r)
| result > 0 && result < r = False
| otherwise = …Run Code Online (Sandbox Code Playgroud)