Beruflich Dokumente
Kultur Dokumente
ON
3D TRANSFORMATION
BY
RAJAT SINGH-131
YASH CHAUBEY-119
Under the Guidance of
Bharati Vidyapeeth
(Deemed to Be University)
#include stdio .h
#include graphics .h
#include math .h
void trans();
//these are left,top,right,bottom parameters for bar3d function
int maxx,maxy,midx,midy;
void main()
int ch;
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
trans();
return 0;
}
int x,y,z,o,x1,x2,y1,y2;
midx=200;
midy=200;
//function to draw 3D rectangular box
bar3d(midx+50,midy-100,midx+100,midy-50,20,1);
delay(1000);
printf("Enter translation factor");
scanf("%d%d",&x,&y);
printf("After translation:");
bar3d(midx+x+50,midy-(y+100),midx+x+100,midy-(y+50),20,1);
}
2. SCALING
You can change the size of an object using scaling transformation. In the scaling process,
you either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the
desired result. The following figure shows the effect of 3D scaling −
In 3D scaling operation, three coordinates are used. Let us assume that the original
coordinates are (X, Y, Z), scaling factors are (SX,SY,Sz)(SX,SY,Sz) respectively, and the
produced coordinates are (X’, Y’, Z’). This can be mathematically represented as shown
below.
C program for 3D scaling is given below-
#include stdio.h
#include graphics.h
#include math.h
void scale();
//these are left,top,right,bottom parameters for bar3d function
int maxx,maxy,midx,midy;
void main()
{
int ch;
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
scale();
return 0;
}
//function for scaling of a 3d object
void scale()
{
int x,y,z,o,x1,x2,y1,y2;
midx=200;
midy=200;
bar3d(midx+50,midy-100,midx+100,midy-50,20,0);
printf("before scaling\n");
printf("Enter scaling factors\n");
scanf("%d %d %d", &x,&y,&z);
printf("After scaling\n");
bar3d(midx+(x*50),midy-(y*100),midx+(x*100),midy-(y*50),20*z,1);
}
3. ROTATION
3D rotation is not same as 2D rotation. In 3D rotation, we have to specify the angle of
rotation along with the axis of rotation. We can perform 3D rotation about X, Y, and Z
axes. They are represented in the matrix form as.
Z-Axis Rotation
R(z)
X-Axis Rotation
Y-Axis Rotation
#include<stdio.h>
#include<graphics.h>
void main()
int gd=DETECT,gm;
int x1,y1,x2,y2 ;
float b1,b2;
float t,deg;
initgraph(&gd,&gm,”c:\\tc\\”);
printf(“Enter the coordinates of Line \n”);
scanf(“%d%d%d%d”,&x1,&y1,&x2,&y2);
setcolor(6);
line(x1,y1,x2,y2);
getch();
//cleardevice();
scanf(“%f”,°);
t=(22*deg)/(180*7);
b1=abs((x2*cos(t))-(y2*sin(t)));
b2=abs((x2*sin(t))+(y2*cos(t)));
l ine(x1,y1,b1,b2);
getch()
closegraph();
}
SHEARING
A transformation that slants the shape of an object is called the shear transformation.
Like in 2D shear, we can shear an object along the X-axis, Y-axis, or Z-axis in 3D.
As shown in the above figure, there is a coordinate P. You can shear it to get a new
coordinate P', which can be represented in 3D matrix form as below −
ROTATION ABOUT AN ARBITRARY AXIS
Having looked at the basic 3D transformations we will now look at a more complex
example involving a combination of these transformations. A commonrequirement is to
rotate an object about an arbitrary axis rather than one of thecoordinate axes. In the notes
on 2D transformations the transformation for rotatingabout an arbitrary point was
derived. This involved shifting the object andpoint so that the point coincides with the
origin, a rotation about the origin andfinally a second shift which is the inverse of the first
to place the object back in itsoriginal position. Similarly a 3D rotation about an arbitrary
axis involves transformingthe object and axis of rotation so that the axis coincides with
one of thecoordinate axes, followed by a rotation about the coordinate axis and
finishingwith a transformation which is the inverse of the first. The individual steps are
as follows:
This derives the rotations required to orientate the axis of rotation so that it is parallel
to one of the coordinate axes.
Figure 8 : 3d projection
1. PERSPECTIVE PROJECTION
In perspective projection, the distance from the center of projection to project plane is
finite and the size of the object varies inversely with distance which looks more
realistic.The distance and angles are not preserved and parallel lines do not remain
parallel. Instead, they all converge at a single point called center of
projection or projection reference point. There are 3 types of perspective
projections:
One-point perspective
A drawing has one-point perspective when it contains only one vanishing point on the
horizon line. This type of perspective is typically used for images of roads, railway tracks,
hallways, or buildings viewed so that the front is directly facing the viewer.Anyobjects
that are made up of lines either directly parallel with the viewer's
line of sight or directly perpendicular (the railroad slats) can be represented with one-
point perspective. These parallel lines converge at the vanishing point.
One-point perspective exists when the picture plane is parallel to two axes of a rectilinear
(or Cartesian) scene – a scene which is composed entirely of linear elements that intersect
only at right angles. If one axis is parallel with the picture plane, then all elements are
either parallel to the picture plane (either horizontally or vertically) or perpendicular to
it. All elements that are parallel to the picture plane are drawn as parallel lines. All
elements that are perpendicular to the picture plane converge at a single point (a
vanishing point) on the horizon.
Two-point perspective
A drawing has two-point perspective when it contains two vanishing points on the
horizon line. In an illustration, these vanishing points can be placed arbitrarily along the
horizon. Two-point perspective can be used to draw the same objects as one-point
perspective, rotated: looking at the corner of a house, or at two forked roads shrinking
into the distance, for example. One point represents one set of parallel lines, the other
point represents the other. Seen from the corner, one wall of a house would recede
towards one vanishing point while the other wall recedes towards the opposite vanishing
point.
Two-point perspective exists when the painting plate is parallel to a Cartesian scene in
one axis (usually the z-axis) but not to the other two axes. If the scene being viewed
consists solely of a cylinder sitting on a horizontal plane, no difference exists in the image
of the cylinder between a one-point and two-point perspective.
Two-point perspective has one set of lines parallel to the picture plane and two sets
oblique to it. Parallel lines oblique to the picture plane converge to a vanishing point,
which means that this set-up will require two vanishing points.
Two-point perspective was demonstrated as early as 1525 by Albrecht Dürer, who
studied perspective by reading Piero and Pacioli's works, in his Unterweisung
dermessungmessung ("Instruction of the measurement")
Three-point perspective
Three-point perspective is often used for buildings seen from above (or below). In
addition to the two vanishing points from before, one for each wall, there is now one for
how the vertical lines of the walls recede. For an object seen from above, this third
vanishing point is below the ground. For an object seen from below, as when the viewer
looks up at a tall building, the third vanishing point is high in space.
Three-point perspective exists when the perspective is a view of a Cartesian scene where
the picture plane is not parallel to any of the scene's three axes. Each of the three
vanishing points corresponds with one of the three axes of the scene. One, two and three-
point perspectives appear to embody different forms of calculated perspective, and are
generated by different methods. Mathematically, however, all three are identical; the
difference is merely in the relative orientation of the rectilinear scene to the viewer.
2. PARALLEL PROJECTION
Parallel projection discards z-coordinate and parallel lines from each vertex on the object
are extended until they intersect the view plane. In parallel projection, we specify a
direction of projection instead of center of projection.
In parallel projection, the distance from the center of projection to project plane is
infinite. In this type of projection, we connect the projected vertices by line segments
which correspond to connections on the original object.
Parallel projections are less realistic, but they are good for exact measurements. In this
type of projections, parallel lines remain parallel and angles are not preserved. Various
types of parallel projections are shown in the following hierarchy.
Orthographic Projection
In orthographic projection the direction of projection is normal to the projection of the
plane. There are three types of orthographic projections −
Front Projection
Top Projection
Side Projection
Oblique Projection
In oblique projection, the direction of projection is not normal to the projection of plane.
In oblique projection, we can view the object better than orthographic projection.
There are two types of oblique projections − Cavalier and Cabinet. The Cavalier
projection makes 45° angle with the projection plane. The projection of a line
perpendicular to the view plane has the same length as the line itself in Cavalier
projection. In a cavalier projection, the foreshortening factors for all three principal
directions are equal.
The Cabinet projection makes 63.4° angle with the projection plane. In Cabinet
projection, lines perpendicular to the viewing surface are projected at ½ their actual
length. Both the projections are shown in the following figure
Isometric Projections
Orthographic projections that show more than one side of an object are
called axonometric orthographic projections. The most common axonometric
projection is an isometric projection where the projection plane intersects each
coordinate axis in the model coordinate system at an equal distance. In this projection
parallelism of lines are preserved but angles are not preserved. The following figure
shows isometric projection −
Figure 14 : Isometric projection of a cube
3D VIEWING
The initial viewing parameters are choosen so as to be able to give an unrestricted view
of the scene. In practice, however, some simplifications are most often used as default
viewing parameters.
The projection plane, shown in Figure, has the view plane defined by a point on the plane
(VRP) and the view plane normal (VPN).
Figure 15 : Initial Viewing Parameters
The VPN gives the orientation of the view plane and is often (but not required to be)
parallel to the view direction. The VPN is used to define a left-handed coordinate
system screen coordinate system. The VUP vector defines a direction which is not parallel
to VPN and is taken to be the viewer's concept of up. VUP need not (but often is taken to)
be perpendicular to VPN. The projection of VUP on the view plane defines the V axis of
the screen coordinate system. The U axis of the screen coordinate system is choosen to
be perpendicular to both (orthogonal to) V and VPN. These vectors are choosen so as to
form a left-handed V, U, VPN 3D coordinate system. The VRP is the origin of the 2D screen
coordinate system. However, VRP is not the origin of the left-handed 3D coordinate
system we wish to define. Its origin is the location of the eye (COP). The coordinates of
COP are defined relative to the VRP using world coordinates.
References:
[1]. http://web.iitd.ac.in/~hegde/cad/lecture/L6_3dtrans.pdf
[2]. https://www.tutorialspoint.com/computer_graphics/3d_transformation.htm
[3]. https://www.slideshare.net/SHIVANISONI11/3d-transformation-in-computer-
graphics
[4]. http://www.it.hiof.no/~borres/j3d/math/threed/p-threed.html
[5]. https://courses.cs.washington.edu/courses/cse457/99au/handouts/lectures/3d-
transformations.pdf
[6]. http://www.netgraphics.sk/3d-transformations