well the problem is, that Vertex and Vector3 are not arrays any more.

You declare your n to be of type Vector3 but the function vertex wants a 3-tupel for nx,ny,nz - so first you have to change the vertex-function to use n instead of nx,ny,nz or you have to provide (n.X,n.Y,n.Z) instead of n to this function.

The other problems are really the same - but here you never said what the p0,p2,p3 are so the compiler interferes them to be of type float*float*float (this is because you use them for the vertex-function)

So now you've got an 3-tuple but you try to do "p02 = p1 - p0" and this is the problem.

Again you can solve this by changing the vertex function from (x,y,z) to p and use p.X,p.Y,p.Z instead of x,y,z in the last line (new Vertex(f x, ...) becomes new Vertex(f p.X, f p.Y, ...))

By on 2/3/2009 1:58 AM ()

Again you can solve this by changing the vertex function from (x,y,z) to p and use p.X,p.Y,p.Z instead of x,y,z in the last line (new Vertex(f x, ...) becomes new Vertex(f p.X, f p.Y, ...))

let triangle (c : Color) (p0, p1, p2) =

let p01 = p1 - p0

let p02 = p2 - p0

let n = Vector3.Normalize(Vector3.Cross(p01, p02))

Array.map (vertex c (float n.X, float n.Y, float n.Z))

[| p0; p01; p02 |]

I don't understand it!

By on 2/3/2009 6:21 AM ()

Well, you haven't posted the definition that the book uses for Vector3. But if it is anything other than:

type Vector3 = float*float*float

then that is why it isn't working. (p0, p1, p2) is a 3-tuple whose first, second, and third arguments are floats.

Here's your code line by line:

1
2
3
4
5
6
7
8
9
(*triangle : Color -> float*float*float* -> (float*float*float)[] *)
let triangle (c : Color) (p0, p1, p2) =
    let p01 = p1 - p0  (*p01 : float*)
    let p02 = p2 - p0  (*p02 : float*)

    (*Doesn't make sense, taking the cross product of 2 floating point numbers is meaningless*)
    let n = Vector3.Normalize(Vector3.Cross(p01, p02))
    Array.map (vertex c (float n.X, float n.Y, float n.Z))
                [| p0; p01; p02 |]

What probably happened is that (p0, p1, p2) is _supposed_ to be an instance of type Vector3 whose x, y, and z components are the floating point values p0, p1, and p2 respectively. But as it's defined, that's not what it appears to be.

What happens if you do this

1
2
3
4
5
6
7
let triangle (c : Color) (p0:Vector3, p1:Vector3, p2:Vector3) =
    let p01 = p1 - p0
    let p02 = p2 - p0

    let n = Vector3.Normalize(Vector3.Cross(p01, p02))
    Array.map (vertex c (float n.X, float n.Y, float n.Z))
                [| p0; p01; p02 |]

Again I don't have the book so I can't actually look at the definition of Vector3 to see if this would work, but if it doesn't, then the fundamental problem is the same. You need a way to make it take vectors as arguments, not single numbers

By on 2/3/2009 7:32 AM ()

Thank-you very much!

let triangle (c : Color) (p0: Vector3, p1: Vector3, p2: Vector3) =

let p01 = p1 - p0

let p02 = p2 - p0

let n = Vector3.Normalize(Vector3.Cross(p01, p02))

Array.map (vertex c (float n.X, float n.Y, float n.Z))

( [| float p0.X, float p0.Y, float p0.Z;

float p01.X, float p01.Y, float p01.Z;

float p02.X, float p02.Y, float p02.Z |] )

By on 2/3/2009 8:54 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper