Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by OlivierWierda · Jul 19, 2018 at 08:00 PM · arrayarraysarraylistinterpolationinterpolate

Linear Interpolation of Array Values

Hey all,

Im currently working on a car physics simulation and I am implementing the torque curve (in Nm)/RPM of an MX5. So I created an Array with a step for every 1000RPM so from : 0 RPM to 7000 RPM :

 public int[] maxMotorTorqueAtRPM = new int[8] { 0, 80, 169, 196, 210, 215, 195, 0 };           
  // arrayposition * 1000 = RPM > maxMotorTorqueAtRPM


So lets say RPM = 2000, then torque is 169nm But because the array is in steps of 1000RPM, i would need to use some interpolation to read the
ex. : torque value for 3421 RPM.

So I make a method :

     public float CheckInterpolatedMaxMotorTorqueAtRPM (int []maxMotorTorqueAtRPM, int currentMotorRPM)
     {
         int interpolatedMaxMotorTorqueAtRPM = Mathf.Lerp (I dont know what to here)
     }  


I've looked all over the web but I cant seem to find the proper syntax to do this

Image for clarification : alt text

direct link to image

The green dots are the points in the Array, and the purple line is what i want to interpolate.

Thanks, Olivier Wierda

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Jul 19, 2018 at 09:01 PM

Just forget about your array and just define your values as an AnimationCurve. Just make a public AnimationCurve variable:

 public AnimationCurve motorTorque;

You can simply sample the curve by using Evaluate

 float val = motorTorque.Evaluate(rpm);

Keep in mind that you can use actual curves or you can set the tangents to be flat is you really want linear interpolation. However since the torque / rmp curve is actually a curve you probably want to actually make it a curve ^^.

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 OlivierWierda · Jul 19, 2018 at 09:23 PM 0
Share

Oh wow! Thank you, this was exactly what I needed indeed!

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

103 People are following this question.

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

Related Questions

How to Clone Array1 into Array2 in Unity? Using JavaScript. 0 Answers

How can you do calculations on two lists? 1 Answer

Unity C# Highscore table 2 Answers

Help with for loop and arrays 3 Answers

Get all GameObjects by variable value 2 Answers


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