85 90 100 125 150 175
8 1.183 1.118 1.006 0.805 0.671 0.575
10 1.847 1.744 1.57 1.256 1.047 0.897
12 2.659 2.511 .. .. ... ...
16 ... ... .. ... ... ..
Say, I have a value of 1.1, I want it to automatically choose the
closest bigger value i.e. 1.118 and say 8 mm diameter at 90 mm spacing.
How can this be implemented? I thought of creating hashes. but it seems
too complicated. If anyone is wondering about the formula it goes like
this.
value = 2 x area of circle / spacing
--
Posted via http://www.ruby-forum.com/.
This sounds an awful lot like homework.
If there is a finite list of spacings, you can figure out the
ideal diameter for each one (by reversing the formula), round each up to
the closest permited diamiter, and choose the one cooresponding to
the smallest computed value (using the given formula). Look at
Array#collect, Array#find, Array#sort, and Array#first.
-- MarkusQ
I assure you, this is no homework. I am complete newbie, and I am
creating a plug-in to work with SketchUp. I could email it you if you
would like to see.
There's a few options.
The simplest is just to iterate through the whole thing, remembering:
* The location of the closest larger value you've previously seen
* How close that value was
For each value, if it is larger, see how close it is; if it's closer than
your previous best guess, it becomes your new best guess. At the end of
the process, you have the best guess.
-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
Create a one-dimensional array where each entry records the value, row
and column number (or row and column headers).
# This should be programmatically done by iterating your array
# not explicitly as I'm showing it here.
Descriptor = Struct.new :row, :col, :value
a = [
Descriptor.new(0, 0, 1.183),
Descriptor.new(0, 1, 1.118),
Descriptor.new(0, 1, 1.006),
# ..etc.
]
# Sort the array by value
a = a.sort_by{ |desc| desc.value }
# Create a method that finds the closest (larger) value in the array
# via a binary search: http://en.wikipedia.org/wiki/Binary_search
# (Left as an exercise for the reader.)
# Now you know what row and column it came from.
reinforcement = [6, 8, 10, 12, 16, 20, 25, 32, 40]
number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
diameters = [8, 10, 12, 16]
spacings = [85, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300]
@shear_links = diameters.product(spacings).map { |d, s| [0.5 * Math::PI
* d ** 2 / s, d, s] }.sort.find { |x,| x > @asw_s }
@compression = reinforcement.product(number).map { |r, n| [0.25 *
Math::PI * r ** 2 * n, r, n] }.sort.find { |x,|x > @comp_steel}
@tension = reinforcement.product(number).map { |r, n| [0.25 * Math::PI *
r ** 2 * n, r, n] }.sort.find { |x,|x > @ten_steel}