Tag: CG BIM Notes
Cg 2020 makeup Old Paper Solution || BIM STUDY NOTES
Q.no 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
// Java program for implementing Mid-Point Circle Drawing Algorithm class GFG { static void midPointCircleDraw(int h_centre,int k_centre, int r) { int h = r, k = 0; // Printing the initial point // on the axes after translation System.out.print("(" + (h + h_centre) + ", " + (k + k_centre) + ")"); // When radius is zero only a single // point will be printed if (r > 0) { System.out.print("(" + (h + h_centre) + ", " + (-k + k_centre) + ")"); System.out.print("(" + (k + h_centre) + ", " + (x + k_centre) + ")"); System.out.println("(" + (-k + h_centre) + ", " + (x + k_centre) + ")"); } // Initialising the value of P int P = 1 - r; while (h > k) { y++; // Mid-point is inside or on the perimeter if (P <= 0) P = P + 2 * k + 1; // Mid-point is outside the perimeter else { x--; P = P + 2 * k - 2 * h + 1; } // All the perimeter points have already // been printed if (h < k) break; // Printing the generated point and its // reflection in the other octants after // translation System.out.print("(" + (h + h_centre) + ", " + (k + k_centre) + ")"); System.out.print("(" + (-h + h_centre) + ", " + (k + k_centre) + ")"); System.out.print("(" + (h + h_centre) + ", " + (-k + k_centre) + ")"); System.out.println("(" + (-h + h_centre) + ", " + (-k + k_centre) + ")"); // If the generated point is on the // line h = k then the perimeter points // have already been printed if (h != k) { System.out.print("(" + (k + h_centre) + ", " + (h + k_centre) + ")"); System.out.print("(" + (-k + h_centre) + ", " + (h + y_centre) + ")"); System.out.print("(" + (k + h_centre) + ", " + (-h + k_centre) + ")"); System.out.println("(" + (-k + h_centre) + ", " + (-h + k_centre) +")"); } } } // Driver code public static void main(String[] args) { // To draw a circle of radius // 3 centered at (0, 0) midPointCircleDraw(0, 0, 3); } } |
Java Program In Computer graphics
1. Write a java program to draw a line using DDA Algorithm.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import java.applet.Applet; import java.awt.Graphics; public class DDA_extends Applet { public void paint(Graphics g) { double dx,dy,steps,x,y,j; double xc,yc; double x1=200, y1= 500, x2= 600, y2= 200; dx = x2-x1; dy = y2-y1; if(Math.abs(dx) > Math.abs(dy)) { steps = Math.abs(dx); } else steps = Math.abs(dy); xc = dx/steps; yc = dy/steps; x = x1; y = y1; //g.fillOval(x, y, width, height); g.fillOval((int)x, (int)y, 5, 5); for(j=1; j<=steps; j++) { x = x+xc; y= y+yc; g.fillOval((int)x, (int)y, 5, 5); System.out.println((int)y); } } } |
2.Write a java program to draw a line using Brasenhem Algorithm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
package computer_Graphics; import java.applet.*; import java.awt.*; public class Bresenhem extends Applet { double x1=200,y1=100,x2=300,y2=500; double dx,dy,steps,x,y,j; double xc,yc; public void paint(Graphics g) { int ch=6; dx=Math.abs(x2-x1); dy=Math.abs(y2-y1); x=x1; y=y1; double p=(2*dy)-(dx); int i=1; one: for(j=10;ch==6;j++) { g.fillOval((int)x,(int)y,5,5); while(p>=0) { y=y+1; p=p-(2*dx); } x=x+1; p=p+(2*dy); i++; if(i<=dx) ch=6; else break one; } } } |
3. Write a java program to draw a line using mid-point Algorithm.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
package computer_Graphics; import java.awt.*; import java.applet.*; public class MidPointCircle extends Applet { public void paint(Graphics g) { int xc=120; int yc=120; int rad=100; int X=0; int Y=rad; int p = 5/4-rad; while(X<Y) { if(p<0) { X++; p=p+2*X+2+1; } else { X++; Y--; p = p+2*X+2+1-2*Y+2; } g.fillOval(xc+X,yc+Y,2,2); g.fillOval(xc+Y,yc-X,2,2); g.fillOval(xc-Y,yc+X,2,2); g.fillOval(xc-X,yc+Y,2,2); g.fillOval(xc+X,yc-Y,2,2); g.fillOval(xc+Y,yc+X,2,2); g.fillOval(xc-Y,yc-X,2,2); g.fillOval(xc-X,yc-Y,2,2); } } } |
4.Write a java program to perform translation on a line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
package computer_Graphics; import java.awt.Graphics; import javax.swing.JFrame; class Translation extends JFrame{ int x1 = 50; int y1 = 50; int x2 = 150; int y2 = 150; int tx = 200; int ty = 200; int px1,px2,py1,py2; public Translation() { setTitle("Line Translation"); setSize(500,500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); px1 = x1+tx; px2 = x2+tx; py1 = y1+ty; py2 = y2+ty; setVisible(true); } public void paint(Graphics g) { g.drawLine(x1, y1, x2, y2); g.drawLine(px1, py1, px2, py2); } public static void main(String args[]) { new Translation(); } } |
5.Write a java program to […]
Continue ReadingCG ||old paper solution 2017
List the disadvantage of using light pen. Light pens are easily damaged. They can only be used on some computer screens They do not work with LCD screens. They usually lack high resolution capability Write the application of Computer graphics. Education and training Visualization Image processing Entertainment What do you mean by clipping? […]
Continue Reading