Created
March 20, 2022 14:20
-
-
Save User4574/c304784e391365557584a3467fb5c2b3 to your computer and use it in GitHub Desktop.
Output cartesian coordinates for the tickmarks along a log scale around a circle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
Maths = Math | |
Intervals = ARGV.shift&.to_i || 2 | |
Radius = ARGV.shift&.to_i || 25 | |
Decimals = ARGV.shift&.to_i || 3 | |
Scale = Maths::PI * 2 / Intervals | |
Width = 1 + Maths.log10(Radius).to_i + 1 + 1 + Decimals | |
def a_tick(mantissa, exponent) | |
tick = mantissa * (10 ** exponent) | |
loc = Scale * (exponent + Maths.log10(mantissa)) | |
x = Radius * Maths.cos(loc) | |
y = Radius * Maths.sin(loc) | |
puts "%#{Intervals + 1}d: (%4.2fr) %#{Width}.#{Decimals}f %#{Width}.#{Decimals}f" % [tick, loc, x, y] | |
end | |
puts "Max #{10 ** Intervals} (#{Intervals} intervals), radius #{Radius}, #{Decimals} decimals" | |
Intervals.times do |exponent| | |
(1..9).each do |mantissa| | |
a_tick(mantissa, exponent) | |
end | |
end | |
a_tick(1, Intervals) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment