How to calculate the transform of a new plane?

I am creating a reference plane after a user closes my PMP. I would like to know the transformation matrix of the plane before it’s being created because you cannot create the plane while the PMP is open.

I create the plane from an edge and a point:

I know the start direction of the edge. This will become the normal of the plane. But how do I calculate the x-axis and y-axis before the plane is created? Which coordinate transformation will SolidWorks use?
image

SW will use the coordinate system of the active document because that is where you are inserting the plane. The point you have will give the translation component of the math transform. You just need the rotation angles of the normal vector with regards to the coordinate system of the active document (where you are inserting the plane).

@artem might have a better idea.

True. The impossible task is getting three rotation angles from a single direction vector for the normal.

I have finally given up because I think it’s mathematically impossible. Now I create the plane before showing the PMP and use the plane’s transformation matrix to create a preview and to create a sketch on that plane when closing the PMP.

Correct me if I’m wrong. Assume the normal vector to be called N. Use the scalar product to get the different angles between x and N, y and N and y and N.
See this:
https://www.intmath.com/vectors/7-vectors-in-3d-space.php

1 Like

Hi Peter,

I don’t know the context of your question, but have you considered using a Coordinate system?
This gives you some more control over the orientation of the X Y Z vectors.
image

For creating a plane those rotations are not important (you can use 0’s as in the code below)
fi. FeatureManager.InsertRefPlane(4, 0, 2, 0, 0, 0)

Eddy

1 Like

I don’t know if those are the angles SolidWorks uses. From what I have found here, they use Euler angles and ZXZ rotations. But of course, such a crucial thing is not documented anywhere in the official help.

@Eddy My goal was to calculate in advance what the plane transformation was going to be. I really needed that plane :smiley:

I have finally found one working solution, spent way too many hours on it and now the client wants to try a completely different approach :stuck_out_tongue: Luckily they don’t mind the extra hours.

Do you mind sharing your solution here ?

Sure. I want to show a PMP and a preview of the geometry that I will create. You cannot create a reference plane when a PMP is open, and hiding the PMP, creating a plane and re-showing the PMP crashes Solidworks. So I create the plane before I open a PMP.

I then use the transformation matrix from the plane to draw the correct temporary geometry for a preview. If the user clicks OK, I create the actual sketch and geometry.

I’ve tried dozens of approaches and only got this to work.

I mean the actual code :smiley: @PeterBrinkhuis

Oh, that I do mind :stuck_out_tongue: It’s for a customer.

1 Like