How to convert a 3D line into a 2D line?

886 Views Asked by At

I wanted to know if there is an algorithm I could use to show a 3D line on a 2D screen. The line is made up of 2 points with X, Y, Z coordinates.

My end goal is to have a bunch of lines that may make up something like cubes, then to be able to move a camera around to view these cubes. The code below is what I have so far.

type Point =
    { X : int
      Y : int
      Z : int }

type Line =
    { A : Point
      B : Point }

let line =
    { A = { X = 0; Y = 0; Z = 0 }
      B = { X = 50; Y = 50; Z = 50 } }
2

There are 2 best solutions below

0
On BEST ANSWER

Draw an isometric box with faint lines and then connect the front left-hand lower corner to the rear right-hand upper corner with a strong line.

Additional post :

I used a land survey system and calculated 2D N,E coordinates of an isometric box as

Point A, N,E of 0 , 0

Point B, N,E of -25.00 , 43.3013

Point C, N,E of 0.00 , 86.6025

Point D, N,E of 50.00 , 86.6025

Then the 2D direction and distance of the required line set in perspective is 60 degrees azimuth at a distance of 100 between Point A and Point D. The true distance of the 3D line would be the Square Root of (50^2 + 50^2 + 50^2) or 86.60 .

0
On

What you want from there? Projections, to take that 3-dimensional point data to a plane to put on screen. To project a line, of course, we project the two points we used to define it.

Of course, the best solution? Find a standard library that implements this stuff already. In Asymptote (a language specializing in graphics, that I use when I want to create a mathematical diagram), that's the "three" module. Over 3000 lines of code, over 150 instances of "projection".