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

  • Home
  • SEARCH
  • 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 3877676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:31:31+00:00 2026-05-19T22:31:31+00:00

I have two points (x 1 , y 1 ) and (x 2 ,y

  • 0

I have two points (x1, y1) and (x2,y2) which represent the location of two entities in my space. I calculate the Euclidian distance between them using Pythagoras’ theorem and everything is wonderful. However, if my space becomes finite, I want to define a new shortest distance between the points that “wraps around” the seams of the map. For example, if I have point A as (10, 10) and point B as (90,10), and my map is 100 units wide, I’d like to calculate the distance between A and B as 20 (out the right edge of the map and back into the left edge), instead of 80, which is the normal Euclidian distance.

I think my issue is that I’m using a coordinate system that isn’t quite right for what I’m trying to do, and that really my flat square map is more of a seamless doughnut shape. Any suggestions for how to implement a system of this nature and convert back and forth from Cartesian coordinates would be appreciated too!

  • 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-05-19T22:31:32+00:00Added an answer on May 19, 2026 at 10:31 pm

    Toroidal plane? Okay, I’ll bite.

    var raw_dx = Math.abs(x2 - x1);
    var raw_dy = Math.abs(y2 - y1);
    
    var dx = (raw_dx < (xmax / 2)) ? raw_dx : xmax - raw_dx;
    var dy = (raw_dy < (ymax / 2)) ? raw_dy : ymax - raw_dy;
    
    var l2dist = Math.sqrt((dx * dx) + (dy * dy));
    

    There’s a correspondence here between the rollover behavior of your x and y coordinates and the rollover behavior of signed integers represented using the base’s complement representation in the method of complements.

    If your coordinate bounds map exactly to the bounds of a binary integer type supported by your language, you can take advantage of the two’s complement representation used by nearly all current machines by simply performing the subtraction directly, ignoring overflow and reinterpreting the result as a signed value of the same size as the original coordinate. In the general case, you’re not going to be that lucky, so the above dance with abs, compare and subtract is required.

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

Sidebar

Related Questions

I have two questions: 1) How can I make an array which points to
I have two points (a line segment) and a rectangle. I would like to
I have an image with two points, aligned something like this: |----------------| | |
Let's say you have a two dimensional plane with 2 points (called a and
I have two applications written in Java that communicate with each other using XML
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
So i have a set of four points in 3D Space. P1 [0, 0,
I have a class, Number , which represents a double with two digits after
So I've been reading Effective Java by Joshua Bloch and noticed two points which
I have two span elements. I want them to sit side-by-side and contain some

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.