# Write a program in c/c to implement cohen-sutherland line clipping algorithm. in this

In these operations the digits are moved, or shifted, to the left or right. Registers in a computer processor have a fixed width, so some bits will be "shifted out" of the register at one end, while the same number of bits are "shifted in" from the other end; the differences between bit shift operators lie in how they determine the values of the shifted-in bits. ## Binary arithmetic

Turtle Graphics Versus Coordinate Graphics "Turtle Graphics" is a simple but powerful approach to creating graphic designs with a computer. Let me give you a very simple example of how it works. Suppose we want to draw a square on the screen, 10 units on a side.

The turtle will leave behind a square. For example, to draw a square tilted by thirty degrees, we need only to type 30 TURN SQUARE The conventional approach to graphics, in which one must specify fixed screen coordinates and the endpoints of each line is much more complicated.

The principle advantage of Turtle Graphics is that it describes shapes in an intrinsic way, without referring to where they are or how they're oriented. The numbers used in Turtle Graphics represent easily visualizable things, like lengths of lines, or angles. A further important aspect of a Turtle Graphics system is the nature of the programming it encourages: END construct shown above is the key to this.

Basic subdesigns can be made into new turtle commands which are then as much a part of the turtle's language as the predefined system commands. These higher-level commands can then be used to define still higher ones, and so on. For example, a simple picture of a house like that in Figure 1 could be drawn with a long sequence of DRAWs and TURNs along with another command for the turtle to move without drawing.

The most complicated aspect of Turtle Graphics is the problem of providing a programming environment in which turtle commands can be executed. There is no need to write an extensible command language processor. The words here are not specifically turtle-oriented.

If the turtle is to move 10 units forward at 30 degrees from the vertical, we need to compute how far up and how far over she goes. For this we use a lookup-table approach. Scaling the values by enables us to store them as single-precision integers. For example, 10 30 SIN leaves 5, or 10 times the sine of 30 degrees, on the stack; and this is how far over the turtle would move. They are best explained by the following example: Screens 5 through 8, culminating in the word CLIP, implement a line-dipping algorithm. We want the turtle to be able to cross the edge of the screen, so that if we execute SQUARE when she is near the top we'll get a clipped box. But the opearing system will refuse to draw a line whose endpoints aren't both within the screen boundaries. Therefore, we must be able to calculate the endpoints of the portion of the line which lies on the screen.

If so, it returns the coordinates of the endpoints of the portion within the dipping rectangle, and a true flag. If not, it returns only a false flag.

But 80 40 CLIP leaves 79 61 1 because only the portion between ,79 and ,61 of the specified line lies inside the dipping rectangle. And CLIP leaves 0 because no part of the line lies inside.

The last screen, number 9, defines the word GRAPHICS for opening the screen in the graphics mode specified by the top the stack, and LINE, which takes the coordinates of two endpoints and draws the clipped part of it on the screen.

If you want to see the dipping in action, before the rest of the code is given in Part 2, try the following:Sutherland Hodgeman polygon clipping algorithm and sums based on it Explain the tests to determine whether the point is inside or outside of the polygon Write function to fill a region whose boundaries are specified by different colors.

Write a procedure to implement the liang –Barsky line – clipping algorithm.