GithubHelp home page GithubHelp logo

hmmhmmhm / circular-spiral-matrix Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 57 KB

A circular spiral coordinate system that evolves in a circular rotation from the center of a Cartesian 2D coordinate system.

JavaScript 13.73% TypeScript 86.27%

circular-spiral-matrix's Introduction

Warning

This formula is still under development.

Circular Spiral Matrix

Spiral Pattern

The getMatrix function generates a circular spiral matrix. This means that the coordinates are arranged in a spiral pattern, starting from the center and moving outwards. The pattern is generated by incrementing the x-coordinate and y-coordinate in a specific order, depending on the current position in the spiral.

What coordinate system it is exploring

The code is exploring the Cartesian 2D plane coordinate system, with 0,0 being the center. The coordinates are returned as an array of integers, where the first element is the x-coordinate and the second element is the y-coordinate.

What pattern it follows

The code generates a circular spiral matrix. This means that the coordinates are arranged in a spiral pattern, starting from the center and moving outwards. The pattern is generated by incrementing the x-coordinate and y-coordinate in a specific order, depending on the current position in the spiral.

Additional details

  • The radius variable represents the radius of the current spiral.
  • The size variable represents the total number of elements in the spiral.
  • The diameter variable represents the diameter of the current spiral.
  • The position variable represents the current position in the spiral.
  • The guide variable determines the direction of the current spiral.

Direction Changes

The direction of the spiral changes every time the position reaches the edge of the current spiral. The direction is determined by the guide variable. The guide variable is calculated by dividing the position by the diameter of the current spiral. The result is then floored to an integer. The possible values of guide are 0, 1, 2, 3, and 4.

  • guide === 0: This indicates that the position is on the right edge of the current spiral. The x-coordinate is decremented, and the y-coordinate is incremented.
  • guide === 1: This indicates that the position is at the top edge of the current spiral. The y-coordinate is decremented, and the x-coordinate is incremented.
  • guide === 2: This indicates that the position is on the left edge of the current spiral. The x-coordinate is incremented, and the y-coordinate is decremented.
  • guide === 3: This indicates that the position is at the bottom edge of the current spiral. The y-coordinate is incremented, and the x-coordinate is decremented.
  • guide === 4: This indicates that the position is in the center of the current spiral. The x-coordinate and y-coordinate are both set to 0.

Position Calculation

The position of the current element in the spiral is calculated using the following formula:

  • position = (1 + index - size) % (radius * 8);
  • index: The index of the current element in the spiral.
  • size: The total number of elements in the spiral.
  • radius: The radius of the current spiral.

The position variable is then used to calculate the x-coordinate and y-coordinate of the current element.

What the code does

The code defines a function called getMatrix that takes an integer n as input and returns a 2D array of integers representing the coordinates of a circular spiral matrix. The matrix is generated in a spiral pattern, starting from the center and moving outwards.

Additional notes

  • The code is written in JavaScript.
  • The code is relatively concise and easy to understand.
  • The code could be improved by adding some comments to explain what it does.

Example

For example, let's consider the element with index 13. The radius of the current spiral is 3, and the size of the current spiral is 48. The position of the element is calculated to be 2. The guide variable is then calculated to be 0. This means that the element is on the right edge of the current spiral. Therefore, the x-coordinate is decremented and the y-coordinate is incremented. The final coordinates of the element are (2, 0).

circular-spiral-matrix's People

Contributors

hmmhmmhm avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.