Skip to content

Instantly share code, notes, and snippets.

@jasonelston
Last active December 11, 2015 00:28
Show Gist options
  • Save jasonelston/4516825 to your computer and use it in GitHub Desktop.
Save jasonelston/4516825 to your computer and use it in GitHub Desktop.
problem getting Math.acos working
# paste this into the console to see the results are sometimes good and then sometimes the error
# Math::DomainError: Numerical argument is out of domain - "acos"
# Error ref - http://www.ruby-doc.org/core-1.9.3/Math/DomainError.html
@loc1 = FactoryGirl.create(:location)
Location.all.each do |location|
location.nearby?(@loc1)
end
### some stuff to break down the algorithm
first_term = @loc1.term1 * @loc1.term2
second_term = @loc1.term3 * @loc1.term4
third_term = Math.cos(@loc1.term5 - @loc1.term6)
# result = first_term + second_term * third_term
# Math.acos(result)
Math.acos(first_term + second_term * third_term)
@jasonelston
Copy link
Author

some of the calibration terms are different on a committed record so when you reference the committed record it's different to the reference of the created record (for the same record id)

irb(main):018:0> l6
=> #<Location id: 1820, lat: -32.73075, lon: 151.37991, term1: -0.5406917001881522, term2: -0.5406917001881522, term3: 0.8412208303101186, term4: 0.8412208303101186, term5: 2.642076906160661, term6: 2.642076906160661, store_id: nil, created_at: "2013-01-13 05:03:39", updated_at: "2013-01-13 05:03:39", calibrated: true>
irb(main):019:0> Location.last
  Location Load (0.4ms)  SELECT "locations".* FROM "locations" ORDER BY "locations"."id" DESC LIMIT 1
=> #<Location id: 1820, lat: -32.73075, lon: 151.37991, term1: -0.540691700188152, term2: -0.540691700188152, term3: 0.841220830310119, term4: 0.841220830310119, term5: 2.64207690616066, term6: 2.64207690616066, store_id: nil, created_at: "2013-01-13 05:03:39", updated_at: "2013-01-13 05:03:39", calibrated: true>
irb(main):020:0> l7 = Location.last
  Location Load (0.9ms)  SELECT "locations".* FROM "locations" ORDER BY "locations"."id" DESC LIMIT 1
=> #<Location id: 1820, lat: -32.73075, lon: 151.37991, term1: -0.540691700188152, term2: -0.540691700188152, term3: 0.841220830310119, term4: 0.841220830310119, term5: 2.64207690616066, term6: 2.64207690616066, store_id: nil, created_at: "2013-01-13 05:03:39", updated_at: "2013-01-13 05:03:39", calibrated: true>
irb(main):021:0> l6
=> #<Location id: 1820, lat: -32.73075, lon: 151.37991, term1: -0.5406917001881522, term2: -0.5406917001881522, term3: 0.8412208303101186, term4: 0.8412208303101186, term5: 2.642076906160661, term6: 2.642076906160661, store_id: nil, created_at: "2013-01-13 05:03:39", updated_at: "2013-01-13 05:03:39", calibrated: true>
irb(main):022:0> l7
=> #<Location id: 1820, lat: -32.73075, lon: 151.37991, term1: -0.540691700188152, term2: -0.540691700188152, term3: 0.841220830310119, term4: 0.841220830310119, term5: 2.64207690616066, term6: 2.64207690616066, store_id: nil, created_at: "2013-01-13 05:03:39", updated_at: "2013-01-13 05:03:39", calibrated: true>
irb(main):023:0> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment