0% found this document useful (0 votes)
32 views4 pages

CG Exp 8

The document describes an experiment to implement reflection of an object using MFC. It discusses reflection as rotating an object 180 degrees. The algorithm section shows code to reflect an object around the x-axis, y-axis, and lines y=x and y=-x. The program section implements this reflection on a figure by creating new point arrays with reflected x and y coordinates and drawing the polygons.

Uploaded by

Atharv Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

CG Exp 8

The document describes an experiment to implement reflection of an object using MFC. It discusses reflection as rotating an object 180 degrees. The algorithm section shows code to reflect an object around the x-axis, y-axis, and lines y=x and y=-x. The program section implements this reflection on a figure by creating new point arrays with reflected x and y coordinates and drawing the polygons.

Uploaded by

Atharv Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO:8

AIM: implement reflection of an object using MFC

THEORY:Reflection is the mirror image of original object. In other words, we can say that it is a rotation
operation with 180°. In reflection transformation, the size of the object does not change.

ALGORITHM:
ABOUT X AXIS:

reflectx (CPoint pt[],CDC * pDC)

CPoint pt1[num];
for (int i =0;i<num;i++)
{
pt1[i].x = pt[i].x;
pt1[i].y = -pt[i].y;
}
pDC-> Polygon(pt1,3);

ABOUT Y AXIS:

reflecty (CPoint pt[],CDC * pDC)

CPoint pt2[num];
for (int i =0;i<num;i++)
{
pt2[i].x = -pt[i].x;
pt2[i].y = pt[i].y;
}
pDC-> Polygon(pt2,3);

ABOUT Y=X

reflectxy(CPoint pt[],CDC * pDC)


{
CPoint pt3[num];
for (int i =0;i<num;i++)
{
pt3[i].y = pt[i].x;
pt3[i].x = pt[i].y;
}
pDC-> Polygon(pt3,3);

PROGRAM:
// MFCApplication7View.cpp : implementation of the CMFCApplication7View class
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "MFCApplication7.h"
#endif

#include "MFCApplication7Doc.h"
#include "MFCApplication7View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CMFCApplication7View

IMPLEMENT_DYNCREATE(CMFCApplication7View, CView)

BEGIN_MESSAGE_MAP(CMFCApplication7View, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
END_MESSAGE_MAP()

// CMFCApplication7View construction/destruction

CMFCApplication7View::CMFCApplication7View() noexcept
{
// TODO: add construction code here

CMFCApplication7View::~CMFCApplication7View()
{
}

BOOL CMFCApplication7View::PreCreateWindow(CREATESTRUCT& cs)


{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);
}

// CMFCApplication7View drawing

void CMFCApplication7View::OnDraw(CDC* pDC)


{
CMFCApplication7Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;

//INITIAL FIGURE
int P[16] = { 658,130,722,110,743,46,764,110,826,130,764,151,743,213,722,151 }; CPoint
pts[8];
pts[0] = CPoint(P[0], P[1]);
pts[1] = CPoint(P[2], P[3]);
pts[2] = CPoint(P[4], P[5]);
pts[3] = CPoint(P[6], P[7]);
pts[4] = CPoint(P[8], P[9]);
pts[5] = CPoint(P[10], P[11]);
pts[6] = CPoint(P[12], P[13]);
pts[7] = CPoint(P[14], P[15]);
pDC->Polygon(pts, 8);pDC->MoveTo(648, 0);pDC->LineTo(648, 694); pDC->MoveTo(1015, 0);pDC-
>LineTo(365, 617); pDC->MoveTo(281, 0);pDC->LineTo(935, 617);pDC->MoveTo(0, 347);
pDC->LineTo(1366, 347);
//ALONG Y-axis
CPoint pts_ry[8];
int P1[16] = { 648 - (P[0] - 648),P[1],648 - (P[2] - 648),P[3],648 - (P[4] - 648),P[5],648 - (P[6] -
648),P[7],648 - (P[8] - 648),P[9],648 - (P[10] - 648),P[11],648 - (P[12] - 648),P[13],648 - (P[14] - 648),P[15] };
pts_ry[0] = CPoint(P1[0], P1[1]);
pts_ry[1] = CPoint(P1[2], P1[3]);
pts_ry[2] = CPoint(P1[4], P1[5]);
pts_ry[3] = CPoint(P1[6], P1[7]);
pts_ry[4] = CPoint(P1[8], P1[9]);
pts_ry[5] = CPoint(P1[10], P1[11]);
pts_ry[6] = CPoint(P1[12], P1[13]);
pts_ry[7] = CPoint(P1[14], P1[15]);
pDC->Polygon(pts_ry, 8);
//ALONG X-axis
CPoint pts_rx[8];
int P2[16] = { P[0],694 - P[1],P[2],694 - P[3],P[4],694 - P[5],P[6],694 - P[7],P[8],694 - P[9],P[10],694 -
P[11],P[12],694 - P[13],P[14],694 - P[15] };
pts_rx[0] = CPoint(P2[0], P2[1]);
pts_rx[1] = CPoint(P2[2], P2[3]);
pts_rx[2] = CPoint(P2[4], P2[5]);
pts_rx[3] = CPoint(P2[6], P2[7]);
pts_rx[4] = CPoint(P2[8], P2[9]);
pts_rx[5] = CPoint(P2[10], P2[11]);
pts_rx[6] = CPoint(P2[12], P2[13]);
pts_rx[7] = CPoint(P2[14], P2[15]);
pDC->Polygon(pts_rx, 8);
//ALONG X= -Y
CPoint pts_rxy[8];
int P3[16] = { 648 - (P[0] - 648),694 - P[1],648 - (P[2] - 648),694 - P[3],648 - (P[4] - 648),694 - P[5],648 -
(P[6] - 648),694 - P[7],648 - (P[8] - 648),694 - P[9],648 - (P[10] - 648),694 - P[11],648 - (P[12] - 648),694 -
P[13],648 - (P[14] - 648),694 - P[15] };
pts_rxy[0] = CPoint(P3[0], P3[1]);
pts_rxy[1] = CPoint(P3[2], P3[3]);
pts_rxy[2] = CPoint(P3[4], P3[5]);
pts_rxy[3] = CPoint(P3[6], P3[7]);
pts_rxy[4] = CPoint(P3[8], P3[9]);
pts_rxy[5] = CPoint(P3[10], P3[11]);
pts_rxy[6] = CPoint(P3[12], P3[13]);
pts_rxy[7] = CPoint(P3[14], P3[15]);
pDC->Polygon(pts_rxy, 8);

//ALONG X=Y
CPoint pts_rxEQy[8];
int temp[16] = { 648 + 347 - P[1],347 - (P[0] - 648),648 + 347 - P[3],347 - (P[2] - 648),648 + 347 - P[5],347
- (P[4] - 648),648 + 347 - P[7],347 - (P[6] - 648),648 + 347 - P[9],347 - (P[8] - 648),648 + 347 - P[11],347 - (P[10] -
648),648 + 347 - P[13],347 - (P[12] - 648),648 + 347 - P[15],347 - (P[14] - 648) };
int P4[16] = { 347 - P[1] + 648,P[0] + 694,P[3] + (648),P[2],P[5] + (648),P[4],P[7] + (648),P[6],P[9] +
(648),P[8],P[11] + (648),P[10],P[13] + (648),P[12],P[15] + (648),P[14] };
pts_rxEQy[0] = CPoint(temp[0], temp[1]);
pts_rxEQy[1] = CPoint(temp[2], temp[3]);
pts_rxEQy[2] = CPoint(temp[4], temp[5]);
pts_rxEQy[3] = CPoint(temp[6], temp[7]);
pts_rxEQy[4] = CPoint(temp[8], temp[9]);
pts_rxEQy[5] = CPoint(temp[10], temp[11]);
pts_rxEQy[6] = CPoint(temp[12], temp[13]);
pts_rxEQy[7] = CPoint(temp[14], temp[15]);

pDC->Polygon(pts_rxEQy, 8);

// TODO: add draw code for native data here


}
// CMFCApplication7View printing
BOOL CMFCApplication7View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMFCApplication7View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMFCApplication7View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CMFCApplication7View diagnostics
#ifdef _DEBUG
void CMFCApplication7View::AssertValid() const
{
CView::AssertValid();
}
void CMFCApplication7View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMFCApplication7Doc* CMFCApplication7View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCApplication7Doc)));
return (CMFCApplication7Doc*)m_pDocument;
}
#endif //_DEBUG
OUTPUT:

CONCLUSION: Reflection along x-axis, y-axis, along x=y and x=-y was applied on a
figure

You might also like