<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>arbitory point | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/arbitory-point/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Fri, 02 Oct 2009 10:11:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>C Program to draw a rectangle and perform the operations.</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 10:11:58 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[draw rectangle]]></category>
		<category><![CDATA[Rotation of rectangle]]></category>
		<category><![CDATA[shear]]></category>
		<category><![CDATA[arbitory point]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=828</guid>

					<description><![CDATA[<p>C Program to draw a rectangle and perform the following operations.<br />
	a. Rotation about the origin followed by translation.<br />
	b. Rotation about an arbitrary point.<br />
	c. Apply X shear and Y shear on the rectangle.</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/">C Program to draw a rectangle and perform the operations.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program to draw a rectangle and perform the following operations.<br />
	a. Rotation about the origin followed by translation.<br />
	b. Rotation about an arbitrary point.<br />
	c. Apply X shear and Y shear on the rectangle.</p>
<pre lang="c" escaped="true" line="1">
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>

void draw (int r[][2])
{
    int i;
    setlinestyle (DOTTED_LINE, 0, 1);
    line (320, 0, 320, 480);
    line (0, 240, 640, 240);

    setlinestyle (SOLID_LINE, 0, 1);
    line (320+r[0][0], 240-r[0][1], 320+r[1][0], 240-r[1][1]);
    line (320+r[0][0], 240-r[0][1], 320+r[3][0], 240-r[3][1]);
    line (320+r[1][0], 240-r[1][1], 320+r[2][0], 240-r[2][1]);
    line (320+r[2][0], 240-r[2][1], 320+r[3][0], 240-r[3][1]);
}

void reset (int r[][2])
{
    int i;
    int val[4][2] = {
			{ 0, 0 },{ 100, 0 },{ 100, 50 },{ 0, 50 }
		    };
	for (i=0; i<4; i++)
    {
	r[i][0] = val[i][0];
	r[i][1] = val[i][1];
    }
}

void rotate (int r[][2], int angle)
{
    int i;
    double ang_rad = (angle * M_PI) / 180;
    for (i=0; i<4; i++)
    {
	double xnew, ynew;
	xnew = r[i][0] * cos (ang_rad) - r[i][1] * sin (ang_rad);
	ynew = r[i][0] * sin (ang_rad) + r[i][1] * cos (ang_rad);
	r[i][0] = xnew;
	r[i][1] = ynew;
    }
}

void shear (int r[][2], int sx, int sy)
{
    int i;
    for (i=0; i<4; i++)
    {
	int xnew, ynew;
	xnew = r[i][0] + r[i][1] * sx;
	ynew = r[i][1] + r[i][0] * sy;
	r[i][0] = xnew;
	r[i][1] = ynew;
    }
}

void translate (int r[][2], int dx, int dy)
{
    int i;
    for (i=0; i<4; i++)
    {
	r[i][0] += dx;
	r[i][1] += dy;
    }
}

void ini()
{
	int gd=DETECT,gm;
	initgraph(&#038;gd,&#038;gm,"..//bgi");
}
void main()
{

	int r[4][2],angle,dx,dy,x, y,choice;

	do
	{
		clrscr();
		printf("1.Rotation about the origin followed by translation\n");
		printf("2.Rotation about an arbitrary point\n");
		printf("3.Shear about the origin\n");
		printf("4.Exit\n\n");
		printf("Enter your choice: ");
		scanf("%d",&#038;choice);
		switch(choice)
		{
			case 1: printf("Enter the rotation angle: ");
				scanf("%d", &#038;angle);
				printf("Enter the x- and y-coordinates for translation: ");
				scanf("%d%d",&#038;dx,&#038;dy);
				ini();
				cleardevice();
				reset(r);
				draw(r);getch();
				rotate(r, angle);
				cleardevice();
				draw(r);getch();
				translate(r,dx,dy);
				cleardevice();
				draw(r);getch();
				closegraph();
				break;
			case 2: printf("Enter the rotation angle: ");
				scanf("%d",&#038;angle);
				printf("Enter the x- and y-coordinates of the point: ");
				scanf("%d%d",&#038;x,&#038;y);
				ini();
				cleardevice();
				reset(r);
				translate(r,x,y);
				draw(r);
				putpixel(320+x,240-y,WHITE);
				getch();
				translate(r,-x,-y);
				draw(r);getch();
				rotate(r,angle);
				draw(r);getch();
				translate(r,x,y);
				cleardevice();
				draw(r);
				putpixel(320+x,240-y,WHITE);
				getch();
				closegraph();
				break;
			case 3: printf("Enter the x- and y-shears: ");
				scanf("%d%d",&#038;x,&#038;y);
				ini();
				reset(r);
				draw(r);getch();
				shear(r, x, y);
				cleardevice();
				draw (r);getch();
				closegraph();
				break;
			case 4: closegraph();
		}
	}while(choice!=4);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/">C Program to draw a rectangle and perform the operations.</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/graphics/c-program-to-draw-a-rectangle-and-perform-the-operations/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
