Wednesday, March 19, 2014

Some Graphics mathematical problems - solutions


1.    What pixels will be marked in drawing a circle center (100,90) and radius 10? using Bresenham's algorithm

Ans:

Take x=0,y=r=10,d=3-2r=3-2*10=-17

Decision variable (d)
x
y
Point with Center (0,0)
Point with Center (100,90)

0
10
(0,10)
(100,100)
-17
1
10
(1,10)
(101,100)
-11
2
10
(2,10)
(102,100)
-1
3
10
(3,10)
(103,100)
13
4
9
(4,9)
(104,99)
-5
5
9
(5,9)
(105,99)
17
6
8
(6,8)
(106,98)
11
7
7
(7,7)
(107,97)

Scaling in C Language

 
 

Point (X,Y) is to be scaled by amount Sx and Sy to location (X',Y')
X' = Sx * X
Y' = Sy * Y
or P' = S * P where
     
P' = [X`,Y`]   , P  = [X,Y]  
             
S  = |  Sx  0  |
     |  0   Sy |

Transformation in C language


 


One of the most common and important tasks in computer graphics is to transform the coordinates (position, orientation, and size) of either objects within the graphical scene or the camera that is viewing the scene. It is also frequently necessary to transform coordinates from one coordinate system to another, (e.g. world coordinates to viewpoint coordinates to screen coordinates.) All of these transformations can be efficiently handled using some simple matrix representations, which are combining multiple transformations into a single composite transform matrix.

bresenham line drawing algorithm in c



 

General idea how Bresenham Line drawing Algorithm works
Uses only integer calculations

Uses distance between ideal y-coordinate and the upper and lower pixel (assuming gentle slope)


Suppose that the line is gently sloping upwards from left to right.

Start by coloring the left-most pixel.

Then, for the next column (that is, for each x value), we have to figure out whether we color the same y or y+1.

DDA Line Drawing Algorithm in C




In computer graphics, digital differential analyzer (DDA) is used for drawing a line between a start and end point Consider an interval [(xstart, ystart), (xend, yend)] by computing for each xi the equations xi = xi-1+1/m, yi = yi-1 + m, where dx = xend − xstart and dy = yend − ystart and m = dy/dx.
A line is sampled at unit intervals in one coordinate and corresponding integer values nearest the line path are determined for other coordinates.

Monday, March 10, 2014

Do U Know?



  1. The minimum time delay between the initiations of two independent memory operations is called
a) access time               b)cycle time    c) transfer time  d) latency time

  1.   Which of the following comments are true?
    1. It is a register
    2. It is a cell in ROM
    3. During execution of the current instruction, its content changes
    4. None of the above

Friday, March 07, 2014

How to take inputs in Java Describe with 2 simple programs





Prog 1:
………………………
Save as input1.java
………………………
import java.util.Scanner;
class input1
{           public static void main(String args[])
            {
                        Scanner scan = new Scanner(System.in);

DO U KNOW?


1. What will be the output of the following arithmetic expression?

5 + 3 * 2 % 10 – 8 * 6

a) –37              b) –42              c) –32              d) –28

Wednesday, March 05, 2014

Write a GUI program in Java that will have two buttons viz., RED and GREEN. If user clicks on RED button the background of the GUI will be painted in red or if user clicks on GREEN button the background of the GUI will be painted green



………………………………………………………………………………………….

Save this file as=> ex.java
………………………………………………………………………………………..
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class ex extends Applet implements ActionListener
{
            Button b1,b2;
           
            public void init()

Some questions with answers from C Language


Can you write another expression which does the same job as ++*ptr;

Ans: (*ptr++)

Are the expressions *ptr++ and ++*ptr same?

Ans; No. ptr++ increments the pointer and not the value pointed by it, whereas, ++*ptr increments the value being pointed to by ptr.