Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kiloblargh · Jun 07, 2012 at 06:34 PM · mathaccelerationmaximumminimum

How would I find multiple peaks and valleys in an array of values?

I know how to get the maximum and minimum values- I just set a variable to zero and then loop through the whole array and change the variable to Mathf.Max(theMax,theArray[i]). Now I'm trying to find the second highest or lowest points, which obviously would be one of the two points immediately on either side of the peak or valley, but that's not what I mean - I'm trying to find peaks and valleys in a sequence, but only the biggest 2 or 3. And it's getting messy.

I know this is more a general programming problem than a Unity-specific one; and there seem to be several approaches to it, but my application is analyzing Input.acceleration data to make tilt controls that don't suck. Could someone who's already got this stuff figured out point me to some example code on the interwebs of an elegant way to go about it?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Starwalker · Jun 07, 2012 at 07:56 PM 0
Share

I'm presu$$anonymous$$g your trying to get a significant "Input" pulse from this array to smooth out tilting. If that is what you want then I have a solution which did work for me.

avatar image coder8 · Jun 07, 2012 at 08:00 PM 0
Share

Can you provide an example of what some data in the array might look like? and point out which data are the ones you would like to find

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Julien-Lynge · Jun 07, 2012 at 08:19 PM

How about taking the differential of the sequence? For each point, do something like

 difference = Mathf.Sign(newVal - prevVal);

When the sign changes from positive to negative, you've hit a peak. When it changes from negative to positive you're at a valley. You can then save out and iterate through the points associated with each peak/valley, or just put them in a SortedList that will automatically sort them from the highest peak to lowest valley.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kiloblargh · Jun 08, 2012 at 01:54 PM 0
Share

Thanks- that's simpler than what I was thinking, and I didn't even know such thing as a SortedList existed.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

mathf.min and mathf.max 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Clarification on how RangeAttribute works 1 Answer

A problem with intersection detection 1 Answer

getting a sum from two scripts 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges