Help with matrix operation in ICE (SOLVED)
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Help with matrix operation in ICE (SOLVED)
Hello all,
I need some help with matrix operation. I am trying to do matrices operation in ICE but its proving quite challenging.
The Matrix formula is as follows:
Q(u,v) = U * Mbezier * P * Mbeziertranspose * Vtranspose
Where
U = [ u^3, u^2, u, 1 ] U between [ 0, 1]
V = [ v^3, v^2, v, 1 ] V between [ 0, 1]
Mbezier is the Matrix basis function for the Bezier4 curve
Mbezier transpose is the transpose of the Bezier4 matrix basis function (which turn out for the Bezier to be the same as MBezier) and
P is the point matrix with each point as follows:
[ P00, P01, P02, P03 ]
[ P10, P11, P12, P13 ]
[ P20, P21, P22, P23 ]
[ P30, P31, P32, P33 ]
I can easily do the first part of the equation, U * MBezier , my problem are as follows:
It does not look like the 4x4 matrix can take a point array (16 points in the form of P(x,y,z) or P(x,y,z,w). How can I feed point position to a 4x4 matrix? Can it be done?
The transpose node does not allow me to connect to the vector to transform the row vector into a column vector. How do you transpose a 3D vector or 4D vector using ICE?
Does the multiply node work correctly for matrix operation?
Right now I am doing it the hard way, breaking up each Point in X matrix, Y matrix and Z matrix, multiplying the vector with matrices and re-assembling the component back into an array, but it is quite cumbersome and can get tricky to debug very quickly.
I am using Softimage 2012, 32 bits system on XP.
Any help is appreciated.
Dan
I need some help with matrix operation. I am trying to do matrices operation in ICE but its proving quite challenging.
The Matrix formula is as follows:
Q(u,v) = U * Mbezier * P * Mbeziertranspose * Vtranspose
Where
U = [ u^3, u^2, u, 1 ] U between [ 0, 1]
V = [ v^3, v^2, v, 1 ] V between [ 0, 1]
Mbezier is the Matrix basis function for the Bezier4 curve
Mbezier transpose is the transpose of the Bezier4 matrix basis function (which turn out for the Bezier to be the same as MBezier) and
P is the point matrix with each point as follows:
[ P00, P01, P02, P03 ]
[ P10, P11, P12, P13 ]
[ P20, P21, P22, P23 ]
[ P30, P31, P32, P33 ]
I can easily do the first part of the equation, U * MBezier , my problem are as follows:
It does not look like the 4x4 matrix can take a point array (16 points in the form of P(x,y,z) or P(x,y,z,w). How can I feed point position to a 4x4 matrix? Can it be done?
The transpose node does not allow me to connect to the vector to transform the row vector into a column vector. How do you transpose a 3D vector or 4D vector using ICE?
Does the multiply node work correctly for matrix operation?
Right now I am doing it the hard way, breaking up each Point in X matrix, Y matrix and Z matrix, multiplying the vector with matrices and re-assembling the component back into an array, but it is quite cumbersome and can get tricky to debug very quickly.
I am using Softimage 2012, 32 bits system on XP.
Any help is appreciated.
Dan
Last edited by Daniel Brassard on 11 Oct 2011, 11:56, edited 1 time in total.
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif
-
dwigfor
- Posts: 395
- Joined: 17 Nov 2009, 16:46
Re: Help with matrix operation in ICE
This sounds a bit beyond me (not that familiar with curves), but have you tried multiply vector by matrix with your 3d or 4d vectors?
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Re: Help with matrix operation in ICE
Hi dwigfor,
Thanks for the reply,
U is a 4D row vector
MBezier is a 4x4 matrix
P is a 4x4 matrix in 3 dimension (one each for x,y,z,w)
MBezier transpose if also a 4x4 matrix and
V Transpose is a 4D column vector
the operation sequence is as follows:
U * MBezier: [1 x 4] * [4 x 4] the result is a [1 x 4] vector using the multiply vector by matrix node
the result is then multiplied with P (4x4 matrix), that is where I have difficulty, I have not found an easy way to create a 4x4 matrix of Point Position vectors.
so [1x4] * [4x4] we end up again with a [1x4] vector
then we multiply with MBezier transposed which is also a [4x4] matrix which again give us a 4D vector [1x4].
Finally, the result of the previous operation is multiplied with a [4x1] column vector which give us the final result Q(u,v), a point on the bezier surface.
In short the notation is:
[1x4] * [4x4] * [4x4] * [4x4] * [4x1] = [1x1]
BTW, writing this answer allowed me to figure out how to create the column vector ..... I just have to change from row to column vector in one of the ICE nodes I created. If this does not work, create a 4x4 matrix where the first column are values and the three others are zeros (I will end up with a [1x4] vector but only the x value is useful, y,z,w will be all zeros) .
Hope that make you understand the concept behind the matrix form. easier to deal with than polynomial formulas!
Dan
Thanks for the reply,
Yes, this is how I deal with most of the operation at this time. To visualize:have you tried multiply vector by matrix with your 3d or 4d vectors?
U is a 4D row vector
MBezier is a 4x4 matrix
P is a 4x4 matrix in 3 dimension (one each for x,y,z,w)
MBezier transpose if also a 4x4 matrix and
V Transpose is a 4D column vector
the operation sequence is as follows:
U * MBezier: [1 x 4] * [4 x 4] the result is a [1 x 4] vector using the multiply vector by matrix node
the result is then multiplied with P (4x4 matrix), that is where I have difficulty, I have not found an easy way to create a 4x4 matrix of Point Position vectors.
so [1x4] * [4x4] we end up again with a [1x4] vector
then we multiply with MBezier transposed which is also a [4x4] matrix which again give us a 4D vector [1x4].
Finally, the result of the previous operation is multiplied with a [4x1] column vector which give us the final result Q(u,v), a point on the bezier surface.
In short the notation is:
[1x4] * [4x4] * [4x4] * [4x4] * [4x1] = [1x1]
BTW, writing this answer allowed me to figure out how to create the column vector ..... I just have to change from row to column vector in one of the ICE nodes I created. If this does not work, create a 4x4 matrix where the first column are values and the three others are zeros (I will end up with a [1x4] vector but only the x value is useful, y,z,w will be all zeros) .
Hope that make you understand the concept behind the matrix form. easier to deal with than polynomial formulas!
Dan
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif
-
grahamef
- Posts: 281
- Joined: 23 Jun 2009, 19:01
Re: Help with matrix operation in ICE
I think you are just supposed to build P by packing the point vectors into a matrix e.g. using nD Vector to nxn Matrix. In the ordinary Bezier equationDaniel Brassard wrote:It does not look like the 4x4 matrix can take a point array (16 points in the form of P(x,y,z) or P(x,y,z,w). How can I feed point position to a 4x4 matrix? Can it be done?
Code: Select all
B(t) = [t^3 t^2 t 1] * Mbezier * P
You don't need to. Once you've multiplied the first 4 terms of your original formula, you're left with a 4x1 matrix multiplied by a 1x4 matrix. This result is the same as the dot product of the two vectors.Daniel Brassard wrote:The transpose node does not allow me to connect to the vector to transform the row vector into a column vector. How do you transpose a 3D vector or 4D vector using ICE?
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Re: Help with matrix operation in ICE
Thanks grahamef for the pointers.
A good overview here:
[url]courses.csusm.edu/cs535xz/Lectures/curve.ppt[/url]
The second form is a pre-compute form to economise computation.
A good overview here:
[url]courses.csusm.edu/cs535xz/Lectures/curve.ppt[/url]
Maybe that is what I need to do, a dot product to get the final result between the [1 x 4] vector and [4 x 1] vector, i will try that. I can also do a cross product to get the normal while at it.You don't need to. Once you've multiplied the first 4 terms of your original formula, you're left with a 4x1 matrix multiplied by a 1x4 matrix. This result is the same as the dot product of the two vectors.
I tried that direction but I don't think I am doing it correctly, the only thing I got was context and type errors. Definitively would like to know how to do it properly. The rest would then be trivial.I think you are just supposed to build P by packing the point vectors into a matrix e.g. using nD Vector to nxn Matrix. In the ordinary Bezier equation.
What you get is a 4x4 matrix for the 16 points (it is a bezier patch that I am building) but with an extra dimension for x,y,z. Most literatures show you the x form and then tell you that y and z are similar as illustrated below.P can be a 4x3 matrix built from the 4 3D point positions so you get a 3D vector for the resulting position.
The second form is a pre-compute form to economise computation.
You do not have the required permissions to view the files attached to this post.
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif
-
grahamef
- Posts: 281
- Joined: 23 Jun 2009, 19:01
Re: Help with matrix operation in ICE
I should have realized it was a patch when I saw the two (u, v) parameters. In that case I think you are doing it correctly by treating the X, Y, and Z components separately.
EDIT: Just to add that you might find it less cumbersome to pack the 16 positions into an array and then use 3D Vector to Scalar to get arrays of the individual X, Y, and Z components. Then you can run each of the three outputs through a custom "Array to Matrix" compound.
EDIT: Just to add that you might find it less cumbersome to pack the 16 positions into an array and then use 3D Vector to Scalar to get arrays of the individual X, Y, and Z components. Then you can run each of the three outputs through a custom "Array to Matrix" compound.
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Re: Help with matrix operation in ICE
Grahamef,
I modified the compound as suggested and its working now. The Dot product did the trick. Maybe you want to test it. Here is the compound, please note that it is unfinished, i.e I want to have selectable basis matrix for u and v in future version. Consider it experimental!
[edit] There is an error in the bezier matrix form. I am getting only u elements instead of u by v elements. I removed the compound for further testing.
[edit] The error was not in the bezier compound. I was not loading the U and V inputs correctly. This is now solved. The compound has been posted on this thread:
viewtopic.php?f=15&t=1802&start=10
Dan
I modified the compound as suggested and its working now. The Dot product did the trick. Maybe you want to test it. Here is the compound, please note that it is unfinished, i.e I want to have selectable basis matrix for u and v in future version. Consider it experimental!
That is how I feed the point position to the matrices for X, W and Z. My problem now is to re-assemble the X, Y and Z component at the output. From the X bezier output you get a matrix that need duplication n times and re-assembled to y and z to create the array. Example, if you have 10 subdiv in u and 10 subdiv in v you end up with 11 X components (from 0 to 10), 11 Y components and 11 Z components. You then need to select each element of the X array and cycle through the Y,Z to reconstruct the array. i.e Index 0 of component x need then to be repeated 11 times, one for each Y,Z then repeat for Index1, Index 2, etc. (which will give you 121 separate points at the end). Rack my brain on it late yesterday but was not successful, yet! That is the last part of the challenge, then I can show/share the ICE tree.Just to add that you might find it less cumbersome to pack the 16 positions into an array and then use 3D Vector to Scalar to get arrays of the individual X, Y, and Z components. Then you can run each of the three outputs through a custom "Array to Matrix" compound.
[edit] There is an error in the bezier matrix form. I am getting only u elements instead of u by v elements. I removed the compound for further testing.
[edit] The error was not in the bezier compound. I was not loading the U and V inputs correctly. This is now solved. The compound has been posted on this thread:
viewtopic.php?f=15&t=1802&start=10
Dan
Last edited by Daniel Brassard on 13 Oct 2011, 12:54, edited 7 times in total.
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif
-
grahamef
- Posts: 281
- Joined: 23 Jun 2009, 19:01
Re: Help with matrix operation in ICE
Sure no problem. I've downloaded it and will take a look when I get a bit of time.
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Re: Help with matrix operation in ICE
I have this issue, here is the X output, I need to repeat the value n time as follows (the repeat is based on the size of the original array so for a size of 6 we get:
-2,-2,-2,-2,-2,-2,-1.2,-1.2,-1.2,-1.2,-1.2,-1.2,-0.4,-0.4,-0.4,-0.4,0.4, ....... and so on like the second picture below.
How can I extract each element and repeat them n time?
Thanks for the help.
Dan
-2,-2,-2,-2,-2,-2,-1.2,-1.2,-1.2,-1.2,-1.2,-1.2,-0.4,-0.4,-0.4,-0.4,0.4, ....... and so on like the second picture below.
How can I extract each element and repeat them n time?
Thanks for the help.
Dan
You do not have the required permissions to view the files attached to this post.
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Re: Help with matrix operation in ICE (solved)
Got it!
After racking my brain for a while, it dawn on me that this is a simple sort in ascending order. So after the modulo trick, I do a sort and voila, a usable array. Sometime the answer is staring you in the face and you don't see it!
Thanks for the help!
Dan
[edit] SOLVED. I now load Q(u,v) correctly and get good results. Q(u,v) equal to (X(u,v), Y(u,v), Z(u,v))
After racking my brain for a while, it dawn on me that this is a simple sort in ascending order. So after the modulo trick, I do a sort and voila, a usable array. Sometime the answer is staring you in the face and you don't see it!
Thanks for the help!
Dan
[edit] SOLVED. I now load Q(u,v) correctly and get good results. Q(u,v) equal to (X(u,v), Y(u,v), Z(u,v))
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif
-
grahamef
- Posts: 281
- Joined: 23 Jun 2009, 19:01
Re: Help with matrix operation in ICE (SOLVED)
Glad you got it working. Is there still something you want me to take a look at?
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Re: Help with matrix operation in ICE (SOLVED)
Hi Grahamef,
It's working fine now (except when i crank the subdivision pass 50, but that is outside the original question and I suspect the problem is in my "build polygon description" nodes).
The surface matrix form work very well and the result can be seen on another thread.
viewtopic.php?f=15&t=1802
I can now push further toward rational bezier, b-spline and NURBS.
Thank you for the help and pointers. Cheers!
Dan
It's working fine now (except when i crank the subdivision pass 50, but that is outside the original question and I suspect the problem is in my "build polygon description" nodes).
The surface matrix form work very well and the result can be seen on another thread.
viewtopic.php?f=15&t=1802
I can now push further toward rational bezier, b-spline and NURBS.
Thank you for the help and pointers. Cheers!
Dan
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif