UNSOLVED Custom convert matrix to polygon

Hi Guys:
I hope to get an inverse matrix through two points, and then give this matrix to my model. So far, I have got two "vectors (point postion)". I'm sorry, I'm a novice in c++ and I'm confused by multiple matrices. I hope to get good results like the example below. 😥 Thank you

[email protected]_y = normalize(@P-point(1,"P",0));
[email protected]_x = normalize(cross({0,1,0},[email protected]_y));
[email protected]_z = normalize(cross([email protected]_x,[email protected]_y));

[email protected] = set([email protected]_x,[email protected]_y,[email protected]_z);

@P *= invert(m);


Vector up = Vector(0,1,0);
Vector yPos = Normalize(point1Pos-point2Pos);
Vector xPos = Normalize(Cross(up,yPos));
Vector zPos = Normalize(Cross(xPos, yPos));

edited by @ferdinand:

@Neekoe said:

I want to customize my axis through this method, thx 🤠

Hello @neekoe,

thank you for reaching out to us. Please edit your initial posting when you want to add information to a question of yours and do not spread out the information over multiple postings at the start of a topic. I have consolidated your posting for you here.

About your Question

I understand that you struggle a bit with the math here and that you want help, but your posting does not contain an actual question, which makes it hard for us to deal with it. As lined out in our Forum Guidelines, we cannot provide support on learning things like math and instead only answer questions about our APIs.

There is the Python Matrix Manual which explains some of the concepts behind matrices/linear transforms in our APIs and also includes an example for what you want to do, construct a frame/matrix from a vector and an up vector. Although I am aware that you are on C++, I would recommend reading it, as it is the closest thing to what you are looking for.

The major problem of your example is that it does not ensure that your vector up and yPos are not parallel or antiparallel (parallel but facing in opposite directions). Since the cross product for such vectors is sort of not defined (it will return the null vector), your whole frame construction will then fall flat in these cases. The Python example deals with that case. If you have questions after reading the manual or regarding your code and our APIs, I would have to ask you to state them explicitly, as Maxon cannot guide you through all of vector math.


@ferdinand thx ferdinand,The example I wrote above is feasible in other software. Maybe Maxon has its own matrix method. I am looking for a way to implement this example through C4d c++. The matrix in the SDK gives me a headache. I need a 3*3 matrix
In addition, I found that my title was wrong, not "custom convert matrix to polygon", but "custom convert matrix to polygon". Thank you very much for helping me merge posts

Hey @neekoe,

@neekoe said in Custom convert matrix to polygon:

@ferdinand thx ferdinand,The example I wrote above is feasible in other software. [...] I am looking for a way to implement this example through C4d c++.

Yeah, I got that 🙂

The matrix in the SDK gives me a headache. I need a 3*3 matrix ...

Well, as I said, the Python example deals with the exact case or yours, is reasonably documented and should be easily transferable.

Both in the Python and C++ API we have multiple matrix types. For most things you just need the type Matrix which is also the type which is subject of the mentioned Python manual. This type is actually just an alias for a Mat3 template, but you can more or less ignore that and what all that template stuff means. If you want to do everything from scratch and want full mathematical control over the carried out transforms (including projections etc.), you will need a matrix of the shape 4x4 and not 3x3 for operations in a space with three degrees of freedom, i.e., you must use the SqrMat4 template. But this is likely all irrelevant for you, if you just want to write a new transform/matrix to the global transform of a BaseObject.


This post is deleted!

@ferdinand I think I understand. I'm trying to convert now. Thank you for your continuous answers