Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on How to proportionally convert a number in the range of -1 and 1 to a number in the range of 0 and 319

Post

How to proportionally convert a number in the range of -1 and 1 to a number in the range of 0 and 319

+3
−2

I have float noise values, between -1 and 1, for every x,y coordinate in a 2D area and I am trying to convert that to a whole number between 0 and 319 which represents a vertical z coordinate to render.

For example,

-1 = 0 and   
1 = 319 but    
0.12345 = ???

How would I go about implementing this efficiently?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

How many such conversions are required (3 comments)
Not sure if I understood entirely your question, but it seems to boil down to a simple set of equatio... (1 comment)
Not sure if I understood entirely your question, but it seems to boil down to a simple set of equatio...
Alexei‭ wrote about 2 years ago

Not sure if I understood entirely your question, but it seems to boil down to a simple set of equations with two variables:

The function is f(x) = a*x + b f(-1) = 0 => -a + b = 0 f(1) = 319 => a + b = 319

=> b = 319 / 2, a = 319 / 2

Of course, this can be generalized to solve the equations for any two points.