Jump to content

Orientation Of A Triangle


Recommended Posts

hi,

i have a given triangle and asigned a normal to it and a custom Attribute vector that points from point 0 to point 1, now I want to align this triangle using this vectors to a other vector set ( the origin orientation)how can I do this? or is there another way to do this. the important part is that later i have to put it back to it's original orientation

thanks in advance

martin

Link to comment
Share on other sites

There may be better more efficient ways but here is what I do.

you have vector x and vector y (y comes from the prim normal)

normalise both x and y

calculate vector z as the cross product of x and y

next turn all 3 into a matrix

x.1 x.2 x.3

y.1 y.2 y.3

z.1 z.2 z.3

invert this matrix

multiplying any point by this matrix will align it with the world axis - which is often handy

translating the aligned points by -center puts it at the origin - you can then do additional scaling and rotation if you like

build a similar matrix as before but for the final position and multiple all the points by this new matrix - this will align your points with the final one, then translate it to the center of the final position.

To put it back just do the reverse.

Also, you can combine all these steps into one matrix if you like then you one need to do the matrix multiplication of the points once. Or twice if you need to reverse everything too.

Edited by sibarrick
Link to comment
Share on other sites

ok, I try it

The first problem I encounter is that about importing attributes into vop context. the import attributeVOP does not allow detail or primitive attributes. I want to create 3 details attribute vectors, position normal and upvector so that I can create a fiull matrix4. how can I imort detail attributes in VOPS. My plan is to create a vopSop that has 2 inputs, one is the geometry that should be copied to the triangle, and one is the triangle as reference space. I'm following more or less the way sibarrick described. I want to cget the 3 vector with the xproduct and then I should have may matrix4 (right?). now if I invrt and multiply this with another matrix4 that contains the point position I should get the new pointosition. (??) can i use the multiplyVop here?

How can I switch between the 2 inputs of the operator for example global variables point postion, there must be a way to get the second input

How can I loop through all points? I see some nodes that seem usefull for this, but any help about this is more than welcome (and needed).

UPDATE: ok some problems are solved, imported the detail params with a parameterVOP. and the processing of all points is done by nature of vex i guess. so my triangle now sticks to the origin. fine. but now that I know that the matrix stuff is working like expected I need to get hold of the second input of the vexSOP. how can I achieve this in VOP? I want to have the triangle in the second input and the gemetry to postion in the first one.

Edited by sanostol
Link to comment
Share on other sites

Found it, thanks sibarrick. I will try it. But I still need to know how I can access the second input of a VopSOP in VOP context. There must be a way. ImportAttributeVOP seems to work only with point Attributes

If you go to sidefx exchange site and download my orient sop I think all the vops to do this are in the hip file that comes with it. If not I can dig them out.
Edited by sanostol
Link to comment
Share on other sites

Found it, thanks sibarrick. I will try it. But I still need to know how I can access the second input of a VopSOP in VOP context. There must be a way. ImportAttributeVOP seems to work only with point Attributes

Hey sanostol,

Here's a quick sketch. It uses the first three points of the second input to build the target frame -- i.e: it doesn't matter if it's an actual triangle, as long as it has >=3 non-colinear points.

Building the matrix is as Simon mentioned, but I'm also including the versions of the matrix that should be used for transforming vectors and normals -- these are slightly different from the main one. This little example transforms the incoming normals as well as the positions, just as a test.

Bringing in the second input is done using the ImportAttributeVOP.

aligntri1.hip

Link to comment
Share on other sites

thanks for the file it cleared up a lot. VOP seems to be very powerfull used by the right person

I totally forgot to take care the normal, and I guess this causes some of my problems

Hey sanostol,

Here's a quick sketch. It uses the first three points of the second input to build the target frame -- i.e: it doesn't matter if it's an actual triangle, as long as it has >=3 non-colinear points.

Building the matrix is as Simon mentioned, but I'm also including the versions of the matrix that should be used for transforming vectors and normals -- these are slightly different from the main one. This little example transforms the incoming normals as well as the positions, just as a test.

Bringing in the second input is done using the ImportAttributeVOP.

aligntri1.hip

Link to comment
Share on other sites

  • 3 weeks later...

Hi Mario,

i studied Your example, ( thanks again for this) and two things are still unclear. It's in the inlinecodeVOP.

$Mvector = (matrix3)$Mpoints;
$Mnormal = invert(transpose($Mvector));

$Mpoints seems to be a matrix4, $Mvector is a Matrix3, so does the (matrix3)$Mpoints term convert it? I'm not familiar with this kind of code.

the second thing that is unclear ( two lines, two problems .... great :D ) is the transpose($Mvector) term, the documentation says that it returns nothing, but assigns the result to the incoming argument ( by reference) , does this mean that the outgoing $Mvector is not transposed, but $Mnormal is the result of the inverted, transposed $Mvector?

invert(transpose($Mvector)) should not work, as transpose returns void, but I see it working here.

Link to comment
Share on other sites

Hi Martin,

$Mpoints seems to be a matrix4, $Mvector is a Matrix3, so does the (matrix3)$Mpoints term convert it? I'm not familiar with this kind of code.

Yes, the type cast converts (in this case) a matrix to a matrix3 by retaining just the linear part of the 4x4 matrix (the upper-left 3x3 sub-matrix).

invert(transpose($Mvector)) should not work, as transpose returns void, but I see it working here.

Huh... I've been using it like that for some time and never noticed it was supposed to return void -- mainly because it seems to work as expected... go figure :P

Anyway. You're right of course. And not just because of the docs (which have been known to be wrong from time to time), but because if you run "vcc -X surface" and look at the two signatures for transpose, you'll see that Mantra also lists them with void returns... which kind'a settles that.

Possibly to do with how VEX interprets a single-parameter-function?

By all means, feel free to change the code to make it legal :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...