Need help in conversion of 3d Points into 2.5D

Hi, I have Vector3 points representing x,y and z. I want those points to make 2D points but the view must be like 2.5D view.
For example, I have this 3D shape

Now I find the points (3D points) of this shape according to camera view. And the output is like:


The above screenshot (black lines) are drawn by using line renderer. I draw lines from the position of Vertex 1 to Vertex 2. The 3D output is okay. But my actual target is get points in 2D only, while the output should be same like in the above screenshot of 3D view.
Now I want same output by using Vector2 having x and y only.
I tried to add Z position of each point with x and y.
i.e

Vector2[] Pos2D(Transform StartPoint, Transform EndPoint)
{
  Vector3 A_Pos = StartPoint.position;
  Vector3 B_Pos = EndPoint.position;

  Vector2 A = new Vector2(A_Pos .x + A_Pos .z,  A_Pos .y - A_Pos .z);
  Vector2 B = new Vector2(B_Pos .x + B_Pos .z,  B_Pos .y - B_Pos .z);
  Vector2[] Pos2Ds = {A, B};
  return Pos2D;
}

The Output is somehow okay but It is not same as 3D view screenshot

Kindly guide me with best method.


6695086--768157--Dingtalk_20210106235901.jpg

6695086--768169--Dingtalk_20210106235912.jpg

Just use some like this:

public static Vector2 OrtographicRepresentation(this Vector3 vector,  Vector2 inclination)
{
    return new Vector2
    (
          vector.x + inclination.x * vector.z,
          vector.y + inclination.y * vector.z
    );
1 Like

Gaze at it with any Camera, and use the WorldPointToScreenPoint() method on the Camera object to effectively “flatten” it to that view.

2 Likes

thanks for the quick answering, may I get some details about parameters i.e. what is “inclination” suppose to be here?

Actually I have to use that Vector2D points in other projects like CAD drawings as well. So I want all points in Vector2. Is there any simple demo for recommendation? Thanks for nice suggestion

That’s trivial, that’s just the object holding your data, and your CAD software doesn’t have a “Unity Vector2” in any case, so you are going to have to export it. In Unity you can cast any Vector3 to a Vector2 anytime you want.

1 Like

No, we have our own company’s CAD system. Also that CAD can export our project points into the actual CAD software points as well. These Vector2 points can be used as x and y in CAD in future

I stand by 100% of my recommendations above.

If you want example / demo code, look in the docs on the Camera API I suggested above.

2 Likes
public Vector2 V3To2(Vector3 point)
{
            Vector2 newPos = Camera.main.WorldToScreenPoint(point);
            newPos /= 100.0f; //If posiition is out of camera screen
            return newPos;
}


You are genious, it worked perfectly. Thank you so much.

6695923--768271--491DFC19-7B0E-4c46-90C8-0354388891E1.png

1 Like