All rights are reserved by Niteesh Kumar.. Theme images by Storman. Powered by Blogger.

Followers

Total Pageviews

Blog Archive

Translate

Thursday, 2 February 2017

Triangle scaling in computer graphics

Transformation of any object in a 2D or 3D plane means the change in the looks of the object by applying certain rules.

 Scaling-

It is one of the transformation technique. Scaling changes the size of an object.This operation is carried out in any polygon by multiplying the scaling factor (Sx,Sy) with each vertex coordinate value (x,y) of the polygon.This results in transform coordinates (x',y') and then we plot the transformed coordinates.

Here is the program to scale a triangle so 
Let's suppose (x1,y1) (x2,y2) (x3,y3) are the coordinates of a triangle and the scaling factor is (Sx,Sy) then transform coordinates will be-




                     (x1',y1')=(Sx*x1,Sy*y1)
                     (x2',y2')=(Sx*x2,Sy*y2) 
                     (x3',y3')=(Sx*x3,Sy*y3)  

One thing you need to keep in mind that theco-ordinates you are providing must form a triangle.

 C program for triangle scaling-



#include<stdio.h>
#include<graphics.h>
#include<math.h>
//function for triangle scaling
void scaling(int x1,int y1,int x2,int y2,int x3,int y3)
{
 int sx,sy,xn1,yn1,xn2,xn3,yn3,yn2,gd,gm;
 printf("enter the scaling vector\n");
 scanf("%d %d",&sx,&sy);
 //scale the co-ordinates of triangle vertices by multiplying the scaling vector
 xn1=x1*sx;
 yn1=y1*sy;
 xn2=x2*sx;
 yn2=y2*sy;
 xn3=x3*sx;
 yn3=y3*sy;
 //initializing the graph
 initgraph(&gd,&gm,"");
 //print the intitial triangle
 line(x1,y1,x2,y2);
 line(x1,y1,x3,y3);
 line(x2,y2,x3,y3);
 delay(600);
 //print the scaled triangle
 line(xn1,yn1,xn2,yn2);
 line(xn1,yn1,xn3,yn3);
 line(xn2,yn2,xn3,yn3);
 delay(600);
 cleardevice();
 
}
int main()
{
 int ch,x1,y1,x2,y2,x3,y3;
 printf("enter the vertex co-ordinates of triangle\n");
 scanf("%d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3);
 scaling(x1,y1,x2,y2,x3,y3);
 return 0;
}

 OUTPUT-

Execution steps for Linux users-

  • first of all, save the code given above with .c extension i.e.(filename.c) 
  • After that open your terminal in the same folder where you have saved the file.
  • Run the command given below in terminal-          
 

             gcc filename.c -lgraph
  • type ./a.out and see the output.
You can scale the same triangle with respect to any vertex.To do this just don't scale that vertex.


6 on: "Triangle scaling in computer graphics"
  1. As soon as we’re absolutely clear we’ll start the proofing procedure. Just about all evidence are sent by way of email till you’re 100% satisfied
    best company logos

    ReplyDelete
  2. They knew what they promised me and delivered on time
    brand consulting firm

    ReplyDelete
  3. That said, it's always overwhelming to consider learning a fresh skill. Before learning how to become web designer, you must consider, "Should I become a web designer?"
    web design melbourne

    ReplyDelete
  4. (Completely dispensing the fact that something has probably already gone wrong, hence the need for synthetic urine.)  Apart from being a lot more hygienic to store, synthetic urine lasts a lot longer than biological urine. Regular urine is very difficult to conceal and store in general. You’ll have to go through several steps to ensure your hair is cleansed and purified. The whole process can take up to 45 minutes to complete. On the plus side, the clarifying shampoo is on the more affordable end for this kind of product. Visit: https://www.urineworld.com/

    ReplyDelete
  5. It’s amazing in support of me to truly have a web site that is valuable meant for my knowledge.
    San Francisco web design

    ReplyDelete