I have been trying to create a simple computer 3D graphics system.
Now, I have defined coordinate system like normal in terms of (x,y,z). One can add different shapes in this system by adding points and specifying which points to connect in order to form a 3D shape.
So, for example creating a simple cube, we add 8 points say
(0,0,0), (s,0,0), (0,0,s), (s,0,s) [forms bottom face of cube]
(0,s,0), (s,s,0), (0,s,s), (s,s,s) [forms top face of cube]
now we can connect these points to create a cube of side length 's'
my problem is that I need to display this system(the axis and the cube) on to a computer screen, which is 2-D i.e I need to find the corresponding 8 points in 2-D plane in terms of (x,y)
Now, a user will define a plane from which this system will be seen. simply by entering a point (of view), say (a,b,c) - So this 'Viewing Plane's' equation will be
ax+ by + cz + d = 0 ( i.e equation of a plane passing through (a,b,c) with normal vector ai+bj+ck)
I can find the projection of all the points of the cube on this plane by this formula
any point (p,q,r)'s projection on plane ax+ by + cz + d=0 is -
x = p - (a*(a*p+b*q+c*r+d))/(a^2+b^2+c^2)
y = q - (b*(a*p+b*q+c*r+d))/(a^2+b^2+c^2)
z = r - (c*(a*p+b*q+c*r+d))/(a^2+b^2+c^2)
now I have projection of all points of the cube on the viewing plane i.e I have a set of points on the same plane, but these coordinates which I have found is with respect to the origin of the original system.
how can I find coordinates of these points wrt to (a,b,c) being the origin and the viewing plane (ax+by+cz+d=0) being the x-y plane .
NOTE that these coordinates must be in 2-D form (since the viewing screen is only 2-D). 'z' component of points should be 0 as they all lie in the same plane.
another NOTE : the perpendicular drawn from origin to the plane ax+by+cz+d=0 meets the plane at (a,b,c). you may know this already.
I hope you understand the question and help me solve this.