Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:36:14+00:00 2026-06-04T23:36:14+00:00

I calculate the distance between the points and if the distances are equal the

  • 0

I calculate the distance between the points and if the distances are equal the point make a square, else no. My code works only if I read the coordinates in the following order A(x, y), B(x, y), C(x, y), D(x, y) or reverse. But if I read like this for example A(x, y), B(x, y), D(x, y), C(x, y) it won’t work because the dist method will calculate the square’s diagonal length. How can I solve this problem?

#include <iostream>
using namespace std;

struct {
    int x;
    int y;
}a[10];

int dist(int x1, int y1, int x2, int y2)
{
    int c1, c2;
    c1 = x2-x1;
    c2 = y2-y1;
    return (c1*c1)+(c2*c2);
}

int main()
{
    int d1, d2, d3, d4;
    for (int i=1; i<=4; i++)
    {
        cout << 'X' << i << '='; cin >> a[i].x;
        cout << 'Y' << i << '='; cin >> a[i].y;
    }
    d1 = dist(a[1].x, a[1].y, a[2].x, a[2].y);
    d2 = dist(a[2].x, a[2].y, a[3].x, a[3].y);
    d3 = dist(a[3].x, a[3].y, a[4].x, a[4].y);
    d4 = dist(a[4].x, a[4].y, a[1].x, a[1].y);
    if(d1==d2 && d1==d3 && d1==d4)
        cout << "Is a square";
    else
        cout << "Is not a square";
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:36:17+00:00Added an answer on June 4, 2026 at 11:36 pm

    Checking the distances is not enough, you’ll need to check at least an angle, as the shape could be a rhombus.

    Checking only angles is also not enough, because you could end up with a rectangle.

    There are a total of 6 distances between the points. Calculate all of them. Out of those 6, four should be equal (call their length x). – this guarantees a rhombus

    The other two should be equal between themselves (call their length y). this guarantees a rectangle

    Put a rhombus and a rectangle together and BAM! – square.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code calculate the distance between two geo points and return the distance
I am using this code to calculate the the distance between two points. I
Hy! I need to calculate the distance between 2 GPS Points. I read this
I'm searching for an algorithm to calculate the average distance between a point and
I am trying to calculate the distance between the first GPS point stored in
I need to calculate the distance (in meters and miles) between two coordinates given
I have to calculate the distance between 2 points, X and Y being the
I need to calculate the distance between two points, but not in the regular
I'm trying to calculate the distance between two points. The two points I stored
In an iPhone App how can you calculate distance between two points in MKMapView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.