{"id":20032589,"url":"https://github.com/akicho8/equation","last_synced_at":"2026-06-02T21:31:34.429Z","repository":{"id":11883523,"uuid":"14445018","full_name":"akicho8/equation","owner":"akicho8","description":"2つの範囲を相互変換するライブラリ","archived":false,"fork":false,"pushed_at":"2017-01-13T10:46:22.000Z","size":242,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-02T05:41:15.491Z","etag":null,"topics":["bezier-curves","math","math-library","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akicho8.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-16T09:54:56.000Z","updated_at":"2016-02-27T13:57:03.000Z","dependencies_parsed_at":"2022-06-29T18:02:06.123Z","dependency_job_id":null,"html_url":"https://github.com/akicho8/equation","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/akicho8/equation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akicho8%2Fequation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akicho8%2Fequation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akicho8%2Fequation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akicho8%2Fequation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akicho8","download_url":"https://codeload.github.com/akicho8/equation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akicho8%2Fequation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33838215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-02T02:00:07.132Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bezier-curves","math","math-library","ruby"],"created_at":"2024-11-13T09:38:23.649Z","updated_at":"2026-06-02T21:31:34.410Z","avatar_url":"https://github.com/akicho8.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+OPTIONS: toc:nil num:nil author:nil creator:nil \\n:nil |:t\n#+OPTIONS: @:t ::t ^:t -:t f:t *:t \u003c:t\n\n* 2つの範囲を相互変換するライブラリ\n\n  - [[https://travis-ci.org/akicho8/equation][Travis]]: [[https://travis-ci.org/akicho8/equation.png]]\n  - [[https://gemnasium.com/akicho8/equation/][Gemnasium]]: [[https://gemnasium.com/akicho8/equation.png]]\n  - [[https://codeclimate.com/github/akicho8/equation][Code Climate]]: [[https://codeclimate.com/github/akicho8/equation.png]]\n\n  [[https://raw.github.com/akicho8/equation/master/examples/all_curve.png]]\n  [[https://raw.github.com/akicho8/equation/master/examples/linear_curve.png]]\n  [[https://raw.github.com/akicho8/equation/master/examples/parabola_curve.png]]\n  [[https://raw.github.com/akicho8/equation/master/examples/bezier_curve.png]]\n  [[https://raw.github.com/akicho8/equation/master/examples/bezier_curve_pull2.png]]\n  [[https://raw.github.com/akicho8/equation/master/examples/mix_curve.png]]\n\n** 使用例\n\nレベルの範囲が 1..99 で強さが 0..9999 の範囲を取るとき、直線の関係にある場合の、レベル30のときの強さは？ またその値からレベルを求めるには？\n\n#+BEGIN_SRC ruby\ncurve = Equation.create(type: :linear, x_range: 1..99, y_range: 0..9999)\nv = curve.y_by_x(30)        # =\u003e 2958.887755102041\ncurve.x_by_y(v)             # =\u003e 30.0\n#+END_SRC\n\nレベルの範囲が 1..99 で経験値が 0..9999 の範囲を取るとき、放物線の関係にある場合の、レベル30のときの経験値は？ またその値からレベルを求めるには？\n\n#+BEGIN_SRC ruby\ncurve = Equation.create(type: :parabola, x_range: 1..99, y_range: 0..9999)\nv = curve.y_by_x(30)        # =\u003e 875.5892336526447\ncurve.x_by_y(v)             # =\u003e 29.999999999999996\n#+END_SRC\n\nレベルの範囲が 1..99 で強さが 0..9999 の範囲を取るとき、左下(0,0)右上(1,1)を結ぶベジェ曲線の中央の制御点を左上に0.25移動させた曲線の関係にある場合の、レベル30のときの強さは？ またその値からレベルを求めるには？\n\n#+BEGIN_SRC ruby\ncurve = Equation.create(type: :bezier, x_range: 1..99, y_range: 0..9999, pull: 0.25)\nv = curve.y_by_x(30)        # =\u003e 6958.219471218414\ncurve.x_by_y(v)             # =\u003e 29.99999999999998\n#+END_SRC\n\n** 間違えやすい所\n\n*** 1. どれだけ経験値を足せば次のレベルになるかを求めるとき\n\n#+BEGIN_SRC ruby\ncurve = Equation.create(type: :parabola, x_range: 1..99, y_range: 0..9999)\n#+END_SRC\n\nまず現在がレベル2でレベル3に移行したいのでそれぞれの必要経験値を求める。\n\n#+BEGIN_SRC ruby\ncurve.y_by_x(2)                 # =\u003e 1.0411286963765098\ncurve.y_by_x(3)                 # =\u003e 4.164514785506039\n#+END_SRC\n\n両方を round してみると\n\n#+BEGIN_SRC ruby\na = curve.y_by_x(2).round       # =\u003e 1\nb = curve.y_by_x(3).round       # =\u003e 4\ndiff = b - a                    # =\u003e 3\n(curve.y_by_x(2) + diff)        # =\u003e 4.04112869637651\n#+END_SRC\n\n4.04 はレベル3のときの 4.16 を越えていない。\nなお、truncate しても ceil しても diff が3になる時点でだめ。\n同じメソッドで小数を削ってしまうのがだめ。\n\n対策1\n\n#+BEGIN_SRC ruby\na = curve.y_by_x(2).floor       # =\u003e 1\nb = curve.y_by_x(3).ceil        # =\u003e 5\ndiff = b - a                    # =\u003e 4\n(curve.y_by_x(2) + diff)        # =\u003e 5.04112869637651\n#+END_SRC\n\n対策2\n\n#+BEGIN_SRC ruby\na = curve.y_by_x(2)             # =\u003e 1.0411286963765098\nb = curve.y_by_x(3)             # =\u003e 4.164514785506039\ndiff = (b - a).ceil             # =\u003e 4\n(curve.y_by_x(2) + diff)        # =\u003e 5.04112869637651\n#+END_SRC\n\n対策3\n\n#+BEGIN_SRC ruby\na = curve.y_by_x(2).ceil        # =\u003e 2\nb = curve.y_by_x(3).ceil        # =\u003e 5\ndiff = b - a                    # =\u003e 3\n(a + diff)                      # =\u003e 5\n#+END_SRC\n\n*** 2. 現在の経験値だとレベルはいくつか求めるとき\n\n現在の経験値 1000 に対応するのはレベル32\n\n#+BEGIN_SRC ruby\ncurve.x_by_y(1000).round        # =\u003e 32\n#+END_SRC\n\nレベル32から経験値を確認すると、\n\n#+BEGIN_SRC ruby\ncurve.y_by_x(32)                # =\u003e 1000.5246772178259\n#+END_SRC\n\n現在の経験値 1000 が 1000.52 を越えていない。\n\n正しい方法\n\n#+BEGIN_SRC ruby\ncurve.x_by_y(1000).truncate     # =\u003e 31\ncurve.y_by_x(31)                # =\u003e 937.0158267388588\n#+END_SRC\n\n現在の経験値 1000 が 937.0 を越えている。\n\n*** 【重要】まとめると──\n\n- レベルから経験値を求める場合の y_by_x の結果は ceil\n- 経験値からレベルを求める場合の x_by_y の結果は floor\n\nこれを使う側でいちいち補正するのも大変なのでモジュールにまとめてある。\nEquation::Base に Equation::LevelSupport を include すれば lv_by_exp と exp_by_lv が使えるようになる。\n(lv_by_exp と exp_by_lv は、それぞれ lv_by_value と value_by_lv にエイリアスしている)\n\n#+BEGIN_SRC ruby\nrequire 'equation/level_support'\nEquation::Base.include(Equation::LevelSupport)\n\ncurve = Equation.create(type: :parabola, x_range: 1..99, y_range: 0..9999)\ncurve.lv_by_exp(1000)           # =\u003e 31\ncurve.exp_by_lv(31)             # =\u003e 938\ncurve.lv_by_exp(938)            # =\u003e 31\n#+END_SRC\n\n経験値 1000 のときのレベルは 31 で、その 31 になるために必要な経験値は 938 で、938 あればレベル 31 になる。\n\n** 不具合\n\n- ベジェ曲線の pull が -0.3 のとき、垂直の直線との交点が取れない\n\n  NUTSU » [as]ベジェ曲線と直線の交点 http://nutsu.com/blog/2007/101701_as_bezjesegment3.html\n  の as で確認しても同様の現象になる。\n\n  とりあえず -0.3 を少しずらして -0.30001 などにすると交点が出てくる。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakicho8%2Fequation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakicho8%2Fequation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakicho8%2Fequation/lists"}