*On 21/02/2010 at 05:47, xxxxxxxx wrote:*

User Information:

Cinema 4D Version: 11.5

Platform: Windows ;

Language(s) : C++ ;

---------

How do I determine the vector positions of the points that make up a given polygon?

~Shawn

]]>*On 22/03/2010 at 07:18, xxxxxxxx wrote:*

Got it. Thanks for everyone's help with this. Finally worked it out. HAHA

~Shawn

]]>*On 20/03/2010 at 05:38, xxxxxxxx wrote:*

I assume you have created a rotation matrix for the cube's selected polygon.

Yes I a have. this is name rotMatrix1

Translate this matrix into global space.

Is this the right way yo do this?

Matrix globalSelPoly = rotMatrix1 * firstSelection->GetMl();

Translate the object's matrix (axis) into global space.

Like this? (firstSelection is the object that represents the first object selected.)

Matrix firstObjGlobal = firstSelection->GetMg();

Translate the new global object's matrix into the polygon's rotation matrix local space.

I'm not sure how to do this. Would you mind giving an example?

Now offset the the object's matrix by the difference of the original rotation and object matrix offsets.

I assume that would look something like this?

objMatrix.off = rotMAtrix.off - objMatrix.off

Thanks,

~Shawn

]]>*On 17/03/2010 at 17:18, xxxxxxxx wrote:*

To translate the rotation Matrix of the cube's polygon to global space, I will need to multiply that by the cube's local matrix?

~Shawn

]]>*On 17/03/2010 at 01:11, xxxxxxxx wrote:*

I assume you have created a rotation matrix for the cube's selected polygon. Translate this matrix into global space. Translate the object's matrix (axis) into global space. Translate the new global object's matrix into the polygon's rotation matrix local space. Now offset the the object's matrix by the difference of the original rotation and object matrix offsets.

cheers,

Matthias

*On 16/03/2010 at 02:47, xxxxxxxx wrote:*

Thanks Matthias,

Here are some screen shots of the whole process.. Hopefully this makes what I am doing a little clearer.

The reason I get only half of the cube being visible is that SetPos() is putting the cube in the position of the center of the polygon. However, the position of the cube is based on the axis of the cube which is in the center of the cube.

I would like to move the axis of the cube to the center of one of the polygons on teh cube so that this polygon is then set on the polygon of the 2nd object instead of the center of the cube.

So after all of that.... I really just need to know how to move the axis of the cube from the center of the cube to the center of one of the polygons of the cube.

LOL

Thanks in advance.

~Shawn

]]>*On 16/03/2010 at 01:01, xxxxxxxx wrote:*

I don't know for sure how the tool is supposed to work. Can you post a screenshot of a different example with a more complex geometry?

cheers,

Matthias

*On 15/03/2010 at 17:49, xxxxxxxx wrote:*

okay .. 100% might have been a bit over zealous. I've got rotations working properly, but now I am having an issue with position.

I use

firstSelection->SetPos((opMatrix * polyLocation));

to set where the object will sit on the polygon (the center).

however, I get this...

I want for it to look like this...

You can see in the second image that the smaller cube is sitting so that the face is right against the polygon of the larger cube. THis is the result I am looking for.

I have tried adding the radius of the smaller cube to the position of the smaller cube but this only works correctly if the object is a cube, otherwise I get some funky results.

Is there a better way to get the postition of the cube to rest polygon to polygon. For example, could I temporarily change the axis of the smaller cube so that when I change the position of the smaller cube, the axis is at the outer edge, and then after I have changed the postiiton, change the axis back.. Is this possible?

How would I change the axis of a polygon object? I have looked at SetModelingAxis() but am not sure how I would use it...

Any help would be greatly appreciated.

Thanks a lot.

~Shawn

]]>*On 15/03/2010 at 14:59, xxxxxxxx wrote:*

Great. I'm glad it worked for you. I have got it now so everything is working 100% for me too.... Good day for us both!

~Shawn

]]>*On 15/03/2010 at 14:34, xxxxxxxx wrote:*

thank you so much! now after incorporating the CalcFaceNormal like you did, everything works fine.

cheers,

Ello

*On 15/03/2010 at 14:20, xxxxxxxx wrote:*

Here's how I am doing it.

```
//ROTATION MATRIX
//GetPoints
Vector c = polyLocation; //midpoint
Vector p = points[lngA]; //polygon point
Vector n = CalcFaceNormal(points, selectedPoly[lngI]); //normal
Vector scale = Vector(Len(opMatrix.v1), Len(opMatrix.v2), Len(opMatrix.v3)); //Get Scale
//Contruct Matrix
Matrix rotMatrix;
rotMatrix.off = p; //The base of the matrix
rotMatrix.v1 = !((p - c)%n); //X axis points toward the second point
rotMatrix.v2 = !(rotMatrix.v1 % n);//Y Axis is perpendicular to the X axis
rotMatrix.v3 = !(n); //Z Axis is along the normal
rotMatrix.v1 = !(rotMatrix.v1 * scale.x);
rotMatrix.v2 = !(rotMatrix.v2 * scale.y);
rotMatrix.v3 = !(rotMatrix.v3 * scale.z);
//place the first object within the rotation matrix
firstSelection->SetMg(rotMatrix);
firstSelection->SetPos((opMatrix * polyLocation));// + firstSelection->GetRad().x);
```

This is working quite well now.. creating a rotation matrix gives me the exact rotation of that specific polygon.

Hope this helps you.

~Shawn

]]>*On 15/03/2010 at 13:51, xxxxxxxx wrote:*

well, what is so strange is that it works for spheres, but not for terrain objects:

http://tempfiles.earthcontrol.de/nm02.jpg

*On 15/03/2010 at 13:41, xxxxxxxx wrote:*

I'm pretty sure that if you are trying to rotate objects based on a polygon then you will need to create a rotation matrix for that polygon and then make the matrix of the object you want to rotate equal to the rotation matrix. That's how I understand it.

]]>*On 15/03/2010 at 13:17, xxxxxxxx wrote:*

no, i am just using clone->SetRot(normal);

is this wrong??

*On 15/03/2010 at 13:12, xxxxxxxx wrote:*

are you creating a rotation matrix based on a specific polygon. ? When I get home I'll show you how I am doing it. I'm driving home right now.

]]>*On 15/03/2010 at 13:05, xxxxxxxx wrote:*

i am using this:

```
padr = ToPoint(baseMesh)->GetPointR();
v = ToPoly(baseMesh)->GetPolygonR();
```

]]>*On 15/03/2010 at 12:56, xxxxxxxx wrote:*

hmmmm... what are you using for the "padr" and for "v"... ?

in

CalcFaceNormal(padr, v)

]]>*On 15/03/2010 at 12:41, xxxxxxxx wrote:*

i am just trying to rotate some clones according to a surface normal. and using CalcFaceNormal results in this:

http://tempfiles.earthcontrol.de/nm01.jpg

*On 15/03/2010 at 12:32, xxxxxxxx wrote:*

What are you trying to do?

~Shawn

]]>*On 15/03/2010 at 12:00, xxxxxxxx wrote:*

does CalcFaceNormal work for you?? when i use it i get only nonsense rotations.

cheers,

ello

*On 15/03/2010 at 03:23, xxxxxxxx wrote:*

yes and yes

source code of CalcFaceNormal()

```
inline Vector CalcFaceNormal(const Vector *padr, const CPolygon &v)
{
if (v.c==v.d)
return !((padr[v.b]-padr[v.a])%(padr[v.c]-padr[v.a]));
else
return !((padr[v.b]-padr[v.d])%(padr[v.c]-padr[v.a]));
}
```

cheers,

Matthias

*On 15/03/2010 at 03:06, xxxxxxxx wrote:*

So to calculate the normal of a quad would I do something like this... Assuming that the points in a quad are A, B, C, and D

QUAD

N = (A-C)%(D-B)

TRIANGLE

N = (A-C)%(B-C)

SOmething like that?

Does CalcFaceNormal() do this for you? or is that something completely different?

Thanks a lot for your help,

~ Shawn

]]>*On 15/03/2010 at 02:49, xxxxxxxx wrote:*

For triangles the normal is the cross product of two edges of the triangle. For quadrangles it's not exactly defined. The easiest way which gives a good result is too use the cross product of the diagonales.

PS. please read up on 3D geometry basics, it will help you in the long run. Most of it can be found through Google and Wikipedia.

cheers,

Matthias

*On 15/03/2010 at 02:47, xxxxxxxx wrote:*

Would I use

~Shawn

]]>*On 15/03/2010 at 02:41, xxxxxxxx wrote:*

Thanks Matthias,

I must not fully understand how to get the normal then. I thought that the normal was A - B. How to I get the value for N then?

THanks,

~Shawn

]]>