Sie sind auf Seite 1von 22

CASE STUDY

ON

3D TRANSFORMATION

BY

RAJAT SINGH-131
YASH CHAUBEY-119
Under the Guidance of

Prof. Mr. Saurabh Saoji

Bharati Vidyapeeth

(Deemed to Be University)

College of Engineering, Pune

Department of Computer Engineering


INTRODUCTION
We have looked at the two-dimensional transformation which are used to manipulate
pictures. Equivalent transformations are needed to manipulate three dimensional
pictures in three-dimensional space. However, not only are transformations useful as a
tool for creating and subsequently altering a picture, they can also help us to visualise the
three-dimensional shape of the resulting picture. We would examine an unfamiliar object
by picking it up and turning it round to look at it from above, below and from the side, or
by holding it at arm’s length or standing back from it. In the same way, transformations
can be used to rotate, translate or scale a picture to obtain an understanding of its shape.
This is particularly important in computer graphics in which the medium for displaying
pictures is the two-dimensional display screen on which depth information may not be
obvious.

Figure 1 : 3d Transformation of a object


In Figure 1 a complex surface is displayed showing the same surface rotated in different
ways. Only by looking at a number of these different views can we begin to understand
the 3D shape of the surface. These notes will develop techniques for expressing three-
dimensional transformations by extending the two-dimensional techniques already
presented.
TYPES OF 3D TRANSFORMATION
1. TRANSLATION
In 3D translation, we transfer the Z coordinate along with the X and Y coordinates. The
process for translation in 3D is similar to 2D translation. A translation moves an object
into a different position on the screen.

The following figure shows the effect of translation −

Figure 2 : Translation in 3d transformation

A point can be translated in 3D by adding translation coordinate (tx,ty,tz)(tx,ty,tz) to the


original coordinate (X, Y, Z) to get the new coordinate (X’, Y’, Z’).
C program for 3D translation is given below-

#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;
}

//function for translation of a 3d object


void trans()

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 −

Figure 3 : Scaling in 3d transformation

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.

Figure 4 : Rotation in 3d transformation


Figure 5 : Geometrical representation of two points in 3d roatation

 Z-Axis Rotation

Z-axis rotation is identical to the 2D case:

x' = x*cos q - y*sin q


y' = x*sin q + y*cos q
z' = z

R(z)
 X-Axis Rotation

X-axis rotation looks like Z-axis rotation if replace:

X axis with Y axis


Y axis with Z axis
Z axis with X axis

So we do the same replacement in the equations:

y' = y*cos q - z*sin q


z' = y*sin q + z*cos q
x' = x

 Y-Axis Rotation

Y-axis rotation looks like Z-axis rotation if replace:

X axis with Z axis


Y axis with X axis
Zaxis with Y axis
So we do the same replacement in equations :

z' = z*cos q - x*sin q


x' = z*sin q + x*cos q
y' = y

C program for 3D rotation of line is given below-

#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();

printf(“Enter the angle of rotation: “);

scanf(“%f”,&deg);

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.

Figure 6 : Shearing in 3d transformation

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:

• Translate so that axis of rotation passes through the origin.


• Rotate object so that axis of rotation coincides with one of the coordinate axes.
• Perform the specified rotation about appropriate coordinate axis.
• Apply inverse rotations to bring axis of rotation back to original orientation.
• Apply inverse translation to bring rotation axis back to original position.

This derives the rotations required to orientate the axis of rotation so that it is parallel
to one of the coordinate axes.

Figure 7 : Rotation about an arbitaray axis


PROJECTIONS
The 3D transformations examined so far have transformed one 3D object intoanother 3D
object. There is another class of transformations which transform 3D object into a 2D
object by projecting it onto a plane. These transformations,known as projections, are of
particular interest in computer graphics in which finished picture must always be
projected onto the flat viewing surface of a graphics display. Projecting a three
dimensional object onto a plane is similar to castinga shadow of the object onto a flat
surface. Illustrates two cases, onewhere the light source is a finite distance from the
object, and the other wherelight source is a long distance from the object, so that the light
rays hitting the object are approximately parallel.

There are two types of projection:


i.Perspective projection
ii. Parallel projection

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

Figure 9 : One point perspective

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")

Figure 10 : Two point perspective in a cube

 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.

Figure 11: Three point perspective in a cube

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

Figure 12: Orthographic projection in there view plan

 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

Figure 13 : Oblique projection

 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

Das könnte Ihnen auch gefallen