>> Do you want to have a function
>> inverse :: (a -> b) -> (b -> a)
>> so that (inverse f) . f = id
>> ?
Yes.

>> that is not possible in the general case.
>> Not to forget that even if it was, not all functions has inverses.
I would like to do this for 3 specific cases, where I would supply the
corresponding inverse functions.

Perhaps I should elaborate.  The specific case I'm looking at is writing a
simple ray-tracer in haskell.  Efficiency issues aside (I'm guessing it
will be horribly slow?), it seems like this problem is perfectly suited for
a functional programming language (limited IO, obvious recursive
algorithm).

The way I was looking at attacking this problem was by representing each
primitive object as some easy to work with base object, followed by any
necessary transformations.  For example, suppose our base plane is y=0, we
could represent all planes with something like:

data Object = Plane [Transformation] where Transformation consists of the
obvious rotate, translate, and scale functions.

This would be really nice for the computation of the intersections because
it seems you could write something like:

intersection::Object->Ray->Ray
intersection (Plane []) ray = --simple ray intersection with y=0 plane
and
intersection (Plane (f:fs)) ray = f(intersection (Plane fs) ((inverse f)
ray))

r=Ray (10,10,10) (10,-2,3)
o=Plane [translate (4,3,2),rotate(pi,pi/2,0)]
i=intersection o r

I'm a newbie to haskell (and raytracers, for that matter), so if I am way
off base, please let me know.
Thanks-
Brett Letner


Reply via email to