NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


Tuesday, October 8, 2013
C graphics program to rotate an object using arbitrary point
/* This program will rotate an object ( triangle) using an arbitrary point */

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int i,xmid,ymid,x1,y1,x2,y2,x3,y3,x,y,dy,dx,p,gap=50,temp,xr,yr;
int x1dash,y1dash,x2dash,y2dash,x3dash,y3dash;
float m;
double theta;
char str[5];
clrscr();
initgraph(&gd,&gm,"..\bgi");

printf("Enter first co-ords of the trianglen");
scanf("%d %d",&x1,&y1);
printf("Enter second co-ords of the trianglen");
scanf("%d %d",&x2,&y2);
printf("Enter third co-ords of the trianglen");
scanf("%d %d",&x3,&y3);

xmid= getmaxx()/2;
ymid= getmaxy()/2;
line(5,ymid,getmaxx()-5,ymid);
line(xmid+3,5,xmid+3,getmaxy()-5);

for( i= xmid+gap;i<getmaxx()-5;i=i+gap)
{
outtextxy(i,ymid-3,"|");
itoa(i-xmid,str,10);
outtextxy(i,ymid+3,str);
}
for( i= ymid-gap;i>5;i=i-gap)
{
outtextxy(xmid,i,"-");
itoa(ymid-i,str,10);
outtextxy(xmid+5,i,str);

}
for( i= xmid-gap;i>5;i=i-gap)
{
outtextxy(i,ymid-3,"|");
itoa(-(xmid-i),str,10);
outtextxy(i-6,ymid+3,str);

}
for( i= ymid+gap;i<getmaxy()-5;i=i+gap)
{
outtextxy(xmid,i,"-");
itoa(-(i-ymid),str,10);
outtextxy(xmid+8,i,str);
}
line(x1+xmid,ymid-y1,x2+xmid,ymid-y2);
line(x2+xmid,ymid-y2,x3+xmid,ymid-y3);
line(x3+xmid,ymid-y3,x1+xmid,ymid-y1);

printf("Enter the degree to rotate");
scanf("%lf",&theta);
theta= ((float) theta *3.14f )/(float)180; // converting theta to radian
printf("Enter the arbitrary point to rotate");
scanf("%d%d",&xr,&yr);
x1dash=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
x2dash=xr+(x2-xr)*cos(theta)-(y2-yr)*sin(theta);
x3dash=xr+(x3-xr)*cos(theta)-(y3-yr)*sin(theta);

y1dash=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
y2dash=yr+(x2-xr)*sin(theta)+(y2-yr)*cos(theta);
y3dash=yr+(x3-xr)*sin(theta)+(y3-yr)*cos(theta);

line(x1dash+xmid,ymid-y1dash,x2dash+xmid,ymid-y2dash);
line(x2dash+xmid,ymid-y2dash,x3dash+xmid,ymid-y3dash);
line(x3dash+xmid,ymid-y3dash,x1dash+xmid,ymid-y1dash);

getch();
closegraph();
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.