0

in my program, I have a solid in top view which I cut using cutting plane (by drawing a line on top view - XY plane). After the solid is cut using this line, I have to show the front face of the cut part on XY plane so I can print the diagram of cross section on paper. So once I have a rectangle of cut face (in front view - XZ plane) and I have to transform it to show in XY plane. How can I do this using VB.net.

I saw this question here: convert 3D plane to 2D and code provided by user Kieth. Is this solution relevant to my problem?

Edit: This edit is related to Nico Schertler's answer. I read up on vectors and basic coordinate geometry. how should I get direction vector? For example, the cut line that cuts my solid cube is defined by: stPt(-1500, 24038, 0) and edPt(45500, 24038, 0). The cut face of the solid is rectangle: pt1(-350, 24038, 0), pt2(1335, 24038, 0), pt3(1335, 24038, -350) and pt4(-350, 24038, -350). I have to transform each coordinate of this rectangle, so that it is lying in XY plane. Currently it is XZ plane. So here, the direction vector is the direction of cut line or each edge of the rectangle? I hope I am not confusing anyone.

Community
  • 1
  • 1
Veda
  • 243
  • 1
  • 15
  • How is the solid object represented? Do you already have the cut shape? Keith's answer seems to do a lot more than you actually need. – Nico Schertler Jun 02 '14 at 09:27
  • Yes, I already have the cut solid. I just want to show its sliced face as 2D. If it is in XY plane already, that's fine. but that won't always be the case. It may be placed anyhow in 3D space. – Veda Jun 02 '14 at 10:05
  • Possibly related question http://math.stackexchange.com/questions/792171/how-to-rotate-a-plane-in-3-d-using-standard-form/804187#804187 – John Alexiou Jun 02 '14 at 11:55

1 Answers1

1

You basically want to transform the 3D-Points to a local 2D coordinate system. We need several things for that:

The coordinates of the local origin. This might be the center of mass of the cut shape or the point average. Anyway, it should lie in the same plane as the cut shape.

The direction of the local up-vector. This is simply (0, 0, 1) because you don't transform this direction.

The direction of the local right-vector. This is given by the cut line's direction. It is of the form (rx, ry, 0). This vector should be normalized.

Then we can calculate the local coordinates (u, v) of a 3D point p as follows:

d = p - origin;
u = dot(d, rightVector);
v = dot(d, upVector); //this is simply d.z because upVector=(0,0,1)

You can use the local coordinates (u, v) to display the cut shape. This can also be expressed using a matrix:

/ u \   / rightVector.x  rightVector.y  rightVector.z \   / d.x \
\ v / = \ upVector.x     upVector.y     upVector.z    / * | d.y |
                                                          \ d.z /
Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • Thanks. I will try this and get back. I am not familiar with vectors and normalization, so I will need to do some reading. But thank you for pointing me in a direction. – Veda Jun 02 '14 at 11:36
  • I plugged in the above logic in my code and it works perfectly!! Thanks Nick Schertler. – Veda Jun 17 '14 at 09:39