THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/08/2011 at 19:08, xxxxxxxx wrote:
Cinema 4D Version: 12
Platform: Windows ; Mac ;
Language(s) : C++ ;
Hey everyone, I want to change the normal of a polygon based on the direction of a line drawn. I want the normal of the polygon to match the direction of the drawn line. How would I accomplish this, is this something I need a NormalTag for?
On 06/08/2011 at 01:28, xxxxxxxx wrote:
To reverse the normal, you need to invert the order of points of the polygon.
a -> d
b -> c
c -> b
d -> a
On 06/08/2011 at 05:19, xxxxxxxx wrote:
Thanks for the reply. I don't so much want to invert the normal as I do want to rotate it a bit. :)
See the attached image.
You can see the first cube the normal follows the world. But the second cube, the normal has rotated to face the mouse cursor which is represented by the red dot. :) This is the effect I desire. I was thinking I might need to make a rotation matrix for the polygon and rotate the entire polygon based on that matrix. But I wondered if anyone knew a better approach. :)
On 06/08/2011 at 06:36, xxxxxxxx wrote:
I don't think that's quite right, Shawn. It's the polygon which has rotated, not the normal. The normal is perpendicular to the polygon, by definition.
So you need to rotate the actual polygon to follow the red dot.
On 06/08/2011 at 06:51, xxxxxxxx wrote:
1. Cool idea :D
2. I think there is only the way rotating the points with the matrix.
You need to calculate the polyogn midpoint, subtract the points positions form it, multiply it with the matrix and then add the polygons midpoint to it again, I think. ;-)
On 06/08/2011 at 08:12, xxxxxxxx wrote:
cool. I will give that a try. Thanks guys.
On 06/08/2011 at 21:56, xxxxxxxx wrote:
Well that didn't give me the results I was hoping.
Here's what I am doing.
First I find the center of the polygon.. this is named ctr.
then I develop a rotation matrix of that polygon by doing this.
//Polygon Rotation Matrix
Vector p = points[a]; //polygon point
Vector n = CalcFaceNormal(points, polys[i]); //Normal
Vector scale = Vector(Len(objPoly->GetMg().v1), Len(objPoly->GetMg().v2), Len(objPoly->GetMg().v3)); //Get Scale
rm.off = ctr; //The base of the matrix
rm.v1 = !((p - ctr) % n); //X axis points toward the second point
rm.v2 = !(rm.v1 % n); //Y Axis is perpendicular to the X axis
rm.v3 = !(n); //Z Axis is along the normal
//Scale the Matrix
rm.v1 = !(rm.v1 * scale.x);
rm.v2 = !(rm.v2 * scale.y);
rm.v3 = !(rm.v3 * scale.z);
Then I find the mouse position in world space with...
//Cursor Position in World Coordinates
Vector msWorld = bd->SW(mx, my, ctr);
//Distance from the mouse to the polygon
Vector dis = msWorld - ctr;
so now what I want to do is to alter the rotation matrix that I found using the directional vector calculated by dis. this vector gives me the distance between the polygon center and the mouse cursor in world space. So I know I will need to alter the points of the polygon based on the "dis" and the rotation matrix. I am just not sure how to do this. I tried the steps you mentioned above nux and I got some very weird results. points went all over. :)
Any thoughts on how to rotate the polygon so that the normal of the polygon is pointing in the same direction as a line drawn between ctr & msWorld?
On 07/08/2011 at 01:59, xxxxxxxx wrote:
Ah, I think you must rotate it about the delta between the Matrix of the normal and the matrix of the wished direction. I think .. I'm not good at matrix-maths, sorry :D
Matrix rm1 = HPBToMatrix(polygonNormal);
Matrix rm2 = HPBToMatrix(mousePosition);
Matrix rm3 = rm2 - rm1;
pointA = pointA * rm3;
pointB = pointB * rm3;
Not quite sure..
On 07/08/2011 at 06:23, xxxxxxxx wrote:
Okay well that puts me on teh right track.. I am not getting the right rotation but at least I am not getting rotation. Thanks nux
On 07/08/2011 at 08:31, xxxxxxxx wrote:
Is it possible to reverse engineer a polygon from only the normal? If I have a line that would represent the normal of a polygon is there a formula for finding points on that plane?
Actually I have the normal and the center point of the polygon. :)
On 07/08/2011 at 14:03, xxxxxxxx wrote:
If you have a normal and the center-point of a polygon, there is no unique mapping. The Points can rotate around the center and always create the "correct polygon".
You have to define at least 1 more vector for the axis-system, then the points have a uniquely defined position in space. If you imagine sitting at the center-point looking in the direction of the normal, it is obvious that we could just "bank" and still be in the center and still be looking along the normal.
So, given the normal and an additional vector, you multiply the two with the cross-product and you will receive the third vector. All together define the axis-system for the polygon.
Once the axis is calculated, you can easily calculate the polygon-points positions.