Giter Club home page Giter Club logo

algorithm-smoothing-angles-in-unity's Introduction

Algorithm: Smoothing out 0-360 degree readouts from a sensor

Description

This was an algorithm I had to come up with in order to use it for my RealSunAR Unity plugin update (Version 2.00).

The problem

When you try to get average between 2 angles, one valued 355 and one valued 5 instead of getting a result of 0 it would output (355 + 5) / 2 = 180

The solution

We need to swift/offset the majority of the values to the 180 part of a circle

  1. Divide the circle into 8 90-degree overlapping sections and count how many values we got in each one
  2. Offset the values according to where most values are found under step 1
  3. Sort the values in order to remove peak values to get rid of false peak readings
  4. Remove the highest and lowest 20% of the values
  5. Find the average of the remaining values
  6. Undo the offset we did in step 2

Usage

Just copy all files into your Assets folder a new project (I created this using Unity 2018.4.0 but should work in all versions). Go to the Assets/Angle Smoothing folder and open the Angle Smoothing scene

Press play!

img

  • As you see I already have sample values in the Angle Smoothing gameobject under it's tab named "Original"
  • The Game window shows a graphic representation of the process
  • The red values represent the original values
  • The green+blue values represent the offset values
  • The blue are the remaining after the removal of peak values
  • Finaly the white shows the solution after it's been swifted back to it's place
  • You can see the results in the console and also the mid steps on the inspector of Angle Smoothing as indexes!

algorithm-smoothing-angles-in-unity's People

Contributors

synthercat avatar

Stargazers

 avatar

Watchers

 avatar  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.