Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Polygon Position

    SDK Help
    0
    47
    36.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 25/02/2010 at 05:47, xxxxxxxx wrote:

      Yes, multiplying a vector with a matrix transforms the vector into the matix' space.

      The Matrix class has several overloaded operators for matrix-matrix and matrix-vector arithmetics.

      cheers,
      Matthias

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 26/02/2010 at 09:38, xxxxxxxx wrote:

        Okay... SO I think I kindof understand a rotation matrix now.   I need to find the vector from the center of the polygon which I did with

          
        polyLocation = (points[lngA] + points[lngB] + points[lngC] + points[lngD]) / 4;  
        

        This gives me a vector that represents the very center of the polygon

        Then I need another point along the same plane which I use points[lngA].  This is the first point in the polygon.

        So mathematically that gives me A & B.   Assuming my equation is C = A x B.     So to get the point which represents the Z axis or the point hovering directly above the polygon face, I simply multiply

          
        Vector rotC =  polyLocation * points[lngA];  
        

        And this should give me my rotation matrix correct?

        So now my question is how do I then rotate my object to match that  rotation matrix?  Here is what I am trying.

          
          //ROTATION MATRIX  
                                        
                                      //GetPoints  
                                      Vector p1 = polyLocation;   
                                      Vector p2 = points[lngA];  
                                        
                                      //Contruct Matrix  
                                      Matrix rotMatrix;  
          
                                      rotMatrix.off = p1; //The base of the matrix  
                                      rotMatrix.v1 = !(p2 - p1); //X axis points toward the second point  
                                      rotMatrix.v2 = !(p2-p1%Vector(0,1,0)); //Y Axis is perpendicular to the X axis  
                                      rotMatrix.v3 = rotMatrix.v1 * rotMatrix.v2;  
          
                                      Vector scale = Vector(Len(rotMatrix.v1), Len(rotMatrix.v2), Len(rotMatrix.v3)); //Get Scale  
                                      Vector pos = rotMatrix.off; ///Get the Position  
                                        
                                      //Create a vector which contains the rotation matrix.  
                                      Vector rot1 = MatrixToHPB(rotMatrix);  
          
          
                                      firstSelection->SetPos(opMatrix * polyLocation);  
                                      firstSelection->SetRot((rot1));      
          
        

        Please let me know if I am way off base here and am going about this completely wrong so that I know not to continue in this way.    Thanks lot for your help.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 01/03/2010 at 06:22, xxxxxxxx wrote:

          Thanks for all your help Jack.  I have officially filled up your PM box.   I didn't notice that what you sent me was different.  Thanks for that.

          ~Shawn

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

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

            Hey folks.  So I believe that I have created the rotation matrix correctly.  And when I click the polygon on the second object the object moves to that polygon correctly, however it does not rotate correctly.  Sometimes it rotates a bit but not the way it should.  I want the firstSelection object to rotate so that it is sitting flush with the polygon no matter what the rotation of the polygon is.    Does anyone see any reason in the following code why this wouldn't be happening?

            Any help would be greatly appreciated.  This one's a bit frustrating.

            for (lngI=0; lngI < lngPolygonCount; lngI++)
                                {
                                    if (bsPoly->IsSelected(lngI))
                                    {
                                        lngA = selectedPoly[lngI].a;
                                        lngB = selectedPoly[lngI].b;
                                        lngC = selectedPoly[lngI].c;
                                        lngD = selectedPoly[lngI].d;
            							
            							//Caclulate the polygon position.
            							if (selectedPoly[lngI].c == selectedPoly[lngI].d) 
            							{
            								polyLocation = (points[lngA] + points[lngB] + points[lngC]) / 3; //Polygon is a Triangle
            								
            							}
            							else
            							{
            								polyLocation = (points[lngA] + points[lngB] + points[lngC] + points[lngD]) / 4; //Polygon is not a Triangle
            							}
              
            							//Align 1st Selection to the polygon of 2nd Selection (X AXIS)
            							if (polyLocation.x > 0)
            							{
            								//ROTATION MATRIX
            								//GetPoints
            								Vector p1 = polyLocation; 
            								Vector p2 = points[lngA];
            								
            								Vector scale = Vector(Len(opMatrix.v1), Len(opMatrix.v2), Len(opMatrix.v3)); //Get Scale
            								
            								//Contruct Matrix
            								Matrix rotMatrix;
              
            								rotMatrix.off = p1; //The base of the matrix
            								rotMatrix.v3 = !(p1); //Z Axis is along the normal
            								rotMatrix.v1 = !(p2 - p1); //X axis points toward the second point
            								rotMatrix.v2 = rotMatrix.v1%rotMatrix.v3;//Y Axis is perpendicular to the X axis
            								rotMatrix.v1 = !(rotMatrix.v3%rotMatrix.v2);//recreated second axis..   using cross product.
            																
            								rotMatrix.v1 = !(rotMatrix.v1 * scale.x);
            								rotMatrix.v2 = !(rotMatrix.v2 * scale.y);
            								rotMatrix.v3 = !(rotMatrix.v3 * scale.z);
            			
            	
            								Vector rot1 = MatrixToHPB(rotMatrix);
            					
            								firstSelection->SetMg(rotMatrix);
            								firstSelection->SetPos((opMatrix * polyLocation) + firstSelection->GetRad().x);
            								//firstSelection->SetRot(rot1);
            	
            							}
              
              
            
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 03/03/2010 at 18:21, xxxxxxxx wrote:

              Do I need the world coordinates of the points I am using for this to work properly?

              ~Shawn

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 09/03/2010 at 17:20, xxxxxxxx wrote:

                I feel like I have done the rotation matrix correctly here.  But my object is not rotating to the normal of the polygon.  Does anyone see anything that I am doing wrong creating the rotation matrix?

                I would GREATLY, appreciate any help anyone could offer.  This one is irritating me because everything I have read about rotation matrices says that I am doing it right.  I am using a vector that represents the center of the polygon (polygonLocation)   I am using another point in the polygon to determine the plane upon which the polygon rests.  I am then using the cross product of those vectors to determine the up vector that is perpendicular to the plane.  So, if my understanding of rotation matrices is correct, this should create a rotation matrix that can then be adapted by an object and that object should rotate to the normal of the polygon.

                However, that is not happening with what I have pasted above.   I am at a loss.  Does anyone see anything that I am doing wrong?

                Thanks so much for anyone who has the time to help me out.

                ~Shawn

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 15/03/2010 at 01:25, xxxxxxxx wrote:

                  Originally posted by xxxxxxxx

                  I am using a vector that represents the center of the polygon (polygonLocation)   I am using another point in the polygon to determine the plane upon which the polygon rests.  I am then using the cross product of those vectors to determine the up vector that is perpendicular to the plane.

                  This part is wrong.

                  Assume that A is the midpoint of your polygon and B is one of the polygon points.
                  N is the polygon normal.

                  You have to build the cross product of (B-A) and N for one of the matrix axes, let's say for V1.
                  Then build the cross product of this new axis and the normal for the second matrix axis, V2.
                  The normal is the third axis of the matrix, V3.
                  The polygon midpoint is the matrix offset, V0 or off.

                  cheers,
                  Matthias

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    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

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

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

                      Would I use

                      CalcFaceNormal()_<_h4_>_

                      ~Shawn

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        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

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                          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

                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                            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

                            1 Reply Last reply Reply Quote 0
                            • H
                              Helper
                              last edited by

                              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                              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

                              1 Reply Last reply Reply Quote 0
                              • H
                                Helper
                                last edited by

                                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

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

                                What are you trying to do?

                                ~Shawn

                                1 Reply Last reply Reply Quote 0
                                • H
                                  Helper
                                  last edited by

                                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                  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

                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    Helper
                                    last edited by

                                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

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

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

                                    in

                                    CalcFaceNormal(padr, v)

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      Helper
                                      last edited by

                                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

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

                                      i am using this:

                                        
                                            padr = ToPoint(baseMesh)->GetPointR();  
                                            v = ToPoly(baseMesh)->GetPolygonR();  
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • H
                                        Helper
                                        last edited by

                                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                        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.

                                        1 Reply Last reply Reply Quote 0
                                        • H
                                          Helper
                                          last edited by

                                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

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

                                          no, i am just using clone->SetRot(normal);
                                          is this wrong??

                                          1 Reply Last reply Reply Quote 0
                                          • H
                                            Helper
                                            last edited by

                                            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                            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.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post