English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Given 4 points, how will u figure out if its a rectangle or not?

2007-06-02 13:10:37 · 6 answers · asked by waterlooguy 2 in Computers & Internet Programming & Design

6 answers

The previous answers suggested by people before me are completely wrong. This is how you would do it:

1) Consider an Array A of 4 points.

2) Take the first point from the array A[0]

3) Compute the slopes between these points A[0],A[1] and A[0], A[2] and A[0],A[3] . Call these slopes m1, m2 and m3


4) Now If( m1*m2)==-1 then
{

if( A[3],A[1] *A[3], A[2]==-1)
cout << "it is a rectangle/square";
else
cout << "Sorry";
}

5) Note, you also have to similarly check for the other 2 cases. And you are done!

6) All the 3 cases fail, then it is not a rectangle/square

2007-06-02 13:51:27 · answer #1 · answered by Anonymous · 1 1

// TestCPPConsole.cpp : Defines the get admission to factor for the console utility. // #incorporate "stdafx.h" #define MAX_LENGTH 21 #define MAX_WIDTH seventy 9 classification Rectangle { deepest: char m_cUseThisChar; int m_iHeight; int m_iWidth; public: Rectangle( char cUseThisChar, int iHeight, int iWidth ) { m_cUseThisChar = cUseThisChar; m_iHeight = iHeight; m_iWidth = iWidth; }; void DrawRectangle( char * szRectangle ) { char * szTemp = ( char * ) malloc( ( m_iWidth + 2 ) * sizeof( char ) ); attempt { szRectangle[ 0 ] = 0; memset( szTemp, 0, m_iWidth + 2 ); memset( szTemp, m_cUseThisChar, m_iWidth ); szTemp[ m_iWidth ] = 'n'; for( int iCnt = a million; iCnt <= m_iHeight; iCnt++ ) strcat( szRectangle, szTemp ); } capture(...) { strcpy( szRectangle, "blunders" ); } if( szTemp != NULL ) { unfastened( szTemp ); szTemp = NULL; } }; }; int _tmain(int argc, _TCHAR* argv[]) { char cUseThisChar; int iHeight, iWidth; printf( "enter the character, and length and width (eg. x %d %d) ):n", MAX_LENGTH, MAX_WIDTH ); scanf( "%c %d %d", &cUseThisChar, &iHeight, &iWidth ); if( iHeight > MAX_LENGTH ) { printf( "you have entered an unlawful fee for the size. It could be between a million and %d.", MAX_LENGTH ); getch(); return a million; } if( iWidth > MAX_WIDTH ) { printf( "you have entered an unlawful fee for the width. It could be between a million and %d.", MAX_WIDTH ); getch(); return a million; } Rectangle rect( cUseThisChar, iHeight, iWidth ); char * szBuffer = ( char * ) malloc( ( ( ( iWidth + 2 ) * iHeight ) + 10 ) * sizeof( char ) ); rect.DrawRectangle( szBuffer ); printf( szBuffer ); unfastened( szBuffer ); szBuffer = NULL; getch(); return 0; } ======================================... Disclaimers: a million. content cloth of stdafx.h report is: //------------------------------------... #pragma as quickly as #define WIN32_LEAN_AND_MEAN #incorporate #incorporate #incorporate #incorporate #incorporate #incorporate //------------------------------------... 2. blunders coping with could be more desirable 3. through deprecation, applications like getch(), strcpy() etc gets warnings. Use different library techniques in case you're picky.

2016-12-18 12:06:57 · answer #2 · answered by vasim 4 · 0 0

if the x is the same on vertice(point) pair 1,2 and pair 3,4 while the y of vertices 1,3 and 2,4 are the same then you have a rectangle.

2007-06-02 13:18:11 · answer #3 · answered by Meldor 2 · 0 1

Check to see if there are two pairs of the same x coordinates as well as two pairs of the same y coordinates.

bool rectangle(x1, y1, x2, y2, x3, y3, x4, y4)
{
return (x1==x2 && x3 == x4 && y1 == y3 && y2 == y4);
}

2007-06-02 13:17:55 · answer #4 · answered by Mearn 4 · 0 1

if Point has coordinates x and y,
and rectangle(Point a, Point b, Point c, Point d) is the method
then it's a rectangle if (a.x==b.x && b.y=c.y && c.x==d.x && d.y==a.y)

2007-06-02 13:21:27 · answer #5 · answered by CinderBlock 5 · 0 1

find the slopes and distances.

2007-06-02 13:54:23 · answer #6 · answered by iyiogrenci 6 · 0 1

fedest.com, questions and answers