mbcp/ja/api/mp_math/utils.html

93 lines
66 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="ja-JP" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>mbcp.mp_math.utils | MBCP ドキュメント</title>
<meta name="description" content="MBCP ライブラリ ドキュメント">
<meta name="generator" content="VitePress v1.3.4">
<link rel="preload stylesheet" href="/assets/style.UiSpMRXd.css" as="style">
<script type="module" src="/assets/app.Dm0AjMTk.js"></script>
<link rel="modulepreload" href="/assets/chunks/theme.BI8DQ_2g.js">
<link rel="modulepreload" href="/assets/chunks/framework.DpC1ZpOZ.js">
<link rel="modulepreload" href="/assets/ja_api_mp_math_utils.md.CrPKk6ui.lean.js">
<link rel="icon" type="image/svg+xml" href="/mbcp-logo.svg">
<link rel="stylesheet" href="https://fonts.font.im/css?family=Cousine:400,400i,700,700i|Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i">
<script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-22f859ac><!--[--><!--]--><!--[--><span tabindex="-1" data-v-3e86afbf></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-3e86afbf> Skip to content </a><!--]--><!----><header class="VPNav" data-v-22f859ac data-v-2a4e514e><div class="VPNavBar has-sidebar top" data-v-2a4e514e data-v-1303e283><div class="wrapper" data-v-1303e283><div class="container" data-v-1303e283><div class="title" data-v-1303e283><div class="VPNavBarTitle has-sidebar" data-v-1303e283 data-v-10b95b50><a class="title" href="/ja/" data-v-10b95b50><!--[--><!--]--><!--[--><img class="VPImage logo" src="/mbcp-logo.svg" alt data-v-f925500d><!--]--><span data-v-10b95b50>MBCP ドキュメント</span><!--[--><!--]--></a></div></div><div class="content" data-v-1303e283><div class="content-body" data-v-1303e283><!--[--><!--]--><div class="VPNavBarSearch search" data-v-1303e283><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="検索を開く"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">検索</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-1303e283 data-v-0fb289c1><span id="main-nav-aria-label" class="visually-hidden" data-v-0fb289c1> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/ja/guide/" tabindex="0" data-v-0fb289c1 data-v-ad4a8b64><!--[--><span data-v-ad4a8b64>スタート</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/ja/refer.html" tabindex="0" data-v-0fb289c1 data-v-ad4a8b64><!--[--><span data-v-ad4a8b64>リファレンス</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/ja/api/" tabindex="0" data-v-0fb289c1 data-v-ad4a8b64><!--[--><span data-v-ad4a8b64>APIリファレンス</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/ja/demo/" tabindex="0" data-v-0fb289c1 data-v-ad4a8b64><!--[--><span data-v-ad4a8b64>インスタンス</span><!--]--></a><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-1303e283 data-v-cd7b67e8 data-v-ec8c49bc><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="Change language" data-v-ec8c49bc><span class="text" data-v-ec8c49bc><span class="vpi-languages option-icon" data-v-ec8c49bc></span><!----><span class="vpi-chevron-down text-icon" data-v-ec8c49bc></span></span></button><div class="menu" data-v-ec8c49bc><div class="VPMenu" data-v-ec8c49bc data-v-9990563e><!----><!--[--><!--[--><div class="items" data-v-cd7b67e8><p class="title" data-v-cd7b67e8>日本語</p><!--[--><div class="VPMenuLink" data-v-cd7b67e8 data-v-79776a7a><a class="VPLink link" href="/api/mp_math/utils.html" data-v-79776a7a><!--[-->简体中文<!--]--></a></div><div class="VPMenuLink" data-v-cd7b67e8 data-v-79776a7a><a class="VPLink link" href="/en/api/mp_math/utils.html" data-v-79776a7a><!--[-->English<!--]--></a></div><div class="VPMenuLink" data-v-cd7b67e8 data-v-79776a7a><a class="VPLink link" href="/zht/api/mp_math/utils.html" data-v-79776a7a><!--[-->繁體中文<!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-1303e283 data-v-2a6692f8><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-2a6692f8 data-v-3a50aa5c data-v-d82e607b><span class="check" data-v-d82e607b><span class="icon" data-v-d82e607b><!--[--><span class="vpi-sun sun" data-v-3a50aa5c></span><span class="vpi-moon moon" data-v-3a50aa5c></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-1303e283 data-v-f3b91b3a data-v-fa18fe49><!--[--><a class="VPSocialLink no-icon" href="https://github.com/snowyk
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 区间限定函数</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> x ([`float`](https://docs.python.org/3/library/functions.html#float)): 值</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> min_ (`float`): 最小值</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> max_ (`float`): 最大值</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> `float`: 限定在区间内的值</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> max</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">min</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(x, max_), min_)</span></span></code></pre></div></details><h3 id="class-approx" tabindex="-1"><em><strong>class</strong></em> <code>Approx</code> <a class="header-anchor" href="#class-approx" aria-label="Permalink to &quot;***class*** `Approx`&quot;"></a></h3><h4 id="def-init-self-value-realnumber" tabindex="-1"><em><strong>def</strong></em> <code>__init__(self, value: RealNumber)</code> <a class="header-anchor" href="#def-init-self-value-realnumber" aria-label="Permalink to &quot;***def*** `__init__(self, value: RealNumber)`&quot;"></a></h4><p><strong>説明</strong>: 用于近似比较对象</p><p><strong>引数</strong>:</p><blockquote><ul><li>value (<a href="./mp_math_typing.html#realnumber"><code>RealNumber</code></a>): 实数</li></ul></blockquote><details><summary><b>ソースコード</b> または <a href="https://github.com/snowykami/mbcp/tree/main/mbcp/mp_math/utils.py#L36" target="_blank">GitHubで表示</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> __init__</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, value: RealNumber):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 用于近似比较对象</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> value ([`RealNumber`](./mp_math_typing#realnumber)): 实数</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> value</span></span></code></pre></div></details><h4 id="def-eq-self-other" tabindex="-1"><em><strong>def</strong></em> <code>__eq__(self, other)</code> <a class="header-anchor" href="#def-eq-self-other" aria-label="Permalink to &quot;***def*** `__eq__(self, other)`&quot;"></a></h4><details><summary><b>ソースコード</b> または <a href="https://github.com/snowykami/mbcp/tree/main/mbcp/mp_math/utils.py#L44" target="_blank">GitHubで表示</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> __eq__</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, other):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> isinstance</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value, (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">float</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> isinstance</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(other, (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">float</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> abs</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> other) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> APPROX</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.raise_type_error(other)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> elif</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> isinstance</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value, Vector3):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> isinstance</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(other, (Vector3, Point3, Plane3, Line3)):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> all</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">([approx(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value.x, other.x), approx(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value.y, other.y), approx(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value.z, other.z)])</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.raise_type_error(other)</span></span></code></pre></div></details><h4 id="def-raise-type-error-self-other" tabindex="-1"><em><strong>def</strong></em> <code>raise_type_error(self, other)</code> <a class="header-anchor" href="#def-raise-type-error-self-other" aria-label="Permalink to &quot;***def*** `raise_type_error(self, other)`&quot;"></a></h4><details><summary><b>ソースコード</b> または <a href="https://github.com/snowykami/mbcp/tree/main/mbcp/mp_math/utils.py#L56" target="_blank">GitHubで表示</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> raise_type_error</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, other):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> raise</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> TypeError</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;Unsupported type: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.value)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> and </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(other)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div></details><h4 id="def-ne-self-other" tabindex="-1"><em><strong>def</strong></em> <code>__ne__(self, other)</code> <a class="header-anchor" href="#def-ne-self-other" aria-label="Permalink to &quot;***def*** `__ne__(self, other)`&quot;"></a></h4><details><summary><b>ソースコード</b> または <a href="https://github.com/snowykami/mbcp/tree/main/mbcp/mp_math/utils.py#L59" target="_blank">GitHubで表示</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> __ne__</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, other):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> not</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">__eq__</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(other)</span></span></code></pre></div></details><h3 id="def-approx-x-float-y-float-0-0-epsilon-float-approx-bool" tabindex="-1"><em><strong>def</strong></em> <code>approx(x: float, y: float = 0.0, epsilon: float = APPROX) -&gt; bool</code> <a class="header-anchor" href="#def-approx-x-float-y-float-0-0-epsilon-float-approx-bool" aria-label="Permalink to &quot;***def*** `approx(x: float, y: float = 0.0, epsilon: float = APPROX) -&gt; bool`&quot;"></a></h3><p><strong>説明</strong>: 判断两个数是否近似相等。或包装一个实数用于判断是否近似于0。</p><p><strong>引数</strong>:</p><blockquote><ul><li>x (<a href="https://docs.python.org/3/library/functions.html#float" target="_blank" rel="noreferrer"><code>float</code></a>): 数1</li><li>y (<code>float</code>): 数2</li><li>epsilon (<code>float</code>): 误差</li></ul></blockquote><p><strong>戻り値</strong>: <a href="https://docs.python.org/3/library/functions.html#bool" target="_blank" rel="noreferrer"><code>bool</code></a>: 是否近似相等</p><details><summary><b>ソースコード</b> または <a href="https://github.com/snowykami/mbcp/tree/main/mbcp/mp_math/utils.py#L63" target="_blank">GitHubで表示</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> approx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">float</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">float</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, epsilon: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">float</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">APPROX</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 判断两个数是否近似相等。或包装一个实数用于判断是否近似于0。</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> x ([`float`](https://docs.python.org/3/library/functions.html#float)): 数1</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> y (`float`): 数2</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> epsilon (`float`): 误差</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> [`bool`](https://docs.python.org/3/library/functions.html#bool): 是否近似相等</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> abs</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> y) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> epsilon</span></span></code></pre></div></details><h3 id="def-sign-x-float-only-neg-bool-false-str" tabindex="-1"><em><strong>def</strong></em> <code>sign(x: float, only_neg: bool = False) -&gt; str</code> <a class="header-anchor" href="#def-sign-x-float-only-neg-bool-false-str" aria-label="Permalink to &quot;***def*** `sign(x: float, only_neg: bool = False) -&gt; str`&quot;"></a></h3><p><strong>説明</strong>: 获取数的符号。</p><p><strong>引数</strong>:</p><blockquote><ul><li>x (<a href="https://docs.python.org/3/library/functions.html#float" target="_blank" rel="noreferrer"><code>float</code></a>): 数</li><li>only_neg (<a href="https://docs.python.org/3/library/functions.html#bool" target="_blank" rel="noreferrer"><code>bool</code></a>): 是否只返回负数的符号</li></ul></blockquote><p><strong>戻り値</strong>: <a href="https://docs.python.org/3/library/functions.html#str" target="_blank" rel="noreferrer"><code>str</code></a>: 符号 + - &quot;&quot;</p><details><summary><b>ソースコード</b> または <a href="https://github.com/snowykami/mbcp/tree/main/mbcp/mp_math/utils.py#L76" target="_blank">GitHubで表示</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> sign</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">float</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, only_neg: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">bool</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">False</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;获取数的符号。</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> x ([`float`](https://docs.python.org/3/library/functions.html#float)): 数</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> only_neg ([`bool`](https://docs.python.org/3/library/functions.html#bool)): 是否只返回负数的符号</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> [`str`](https://docs.python.org/3/library/functions.html#str): 符号 + - &quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;+&#39;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> not</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> only_neg </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;&#39;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> elif</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;-&#39;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;&#39;</span></span></code></pre></div></details><h3 id="def-sign-format-x-float-only-neg-bool-false-str" tabindex="-1"><em><strong>def</strong></em> <code>sign_format(x: float, only_neg: bool = False) -&gt; str</code> <a class="header-anchor" href="#def-sign-format-x-float-only-neg-bool-false-str" aria-label="Permalink to &quot;***def*** `sign_format(x: float, only_neg: bool = False) -&gt; str`&quot;"></a></h3><p><strong>説明</strong>: 格式化符号数 -1 -&gt; -1 1 -&gt; +1 0 -&gt; &quot;&quot;</p><p><strong>引数</strong>:</p><blockquote><ul><li>x (<a href="https://docs.python.org/3/library/functions.html#float" target="_blank" rel="noreferrer"><code>float</code></a>): 数</li><li>only_neg (<a href="https://docs.python.org/3/library/functions.html#bool" target="_blank" rel="noreferrer"><code>bool</code></a>): 是否只返回负数的符号</li></ul></blockquote><p><strong>戻り値</strong>: <a href="https://docs.python.org/3/library/functions.html#str" target="_blank" rel="noreferrer"><code>str</code></a>: 符号 + - &quot;&quot;</p><details><summary><b>ソースコード</b> または <a href="https://github.com/snowykami/mbcp/tree/main/mbcp/mp_math/utils.py#L92" target="_blank">GitHubで表示</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> sign_format</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">float</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, only_neg: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">bool</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">False</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;格式化符号数</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> -1 -&gt; -1</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 1 -&gt; +1</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 0 -&gt; &quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Args:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> x ([`float`](https://docs.python.org/3/library/functions.html#float)): 数</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> only_neg ([`bool`](https://docs.python.org/3/library/functions.html#bool)): 是否只返回负数的符号</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> Returns:</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> [`str`](https://docs.python.org/3/library/functions.html#str): 符号 + - &quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> not</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> only_neg </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> elif</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> x </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{abs</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(x)</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;&#39;</span></span></code></pre></div></details></div></div></main><footer class="VPDocFooter" data-v-40342069 data-v-a4b38bd6><!--[--><!--]--><div class="edit-info" data-v-a4b38bd6><div class="edit-link" data-v-a4b38bd6><a class="VPLink link vp-external-link-icon no-icon edit-link-button" href="https://github.com/snowykami/mbcp/tree/main/mbcp//mp_math/utils.py" target="_blank" rel="noreferrer" data-v-a4b38bd6><!--[--><span class="vpi-square-pen edit-link-icon" data-v-a4b38bd6></span> このページをGitHubで編集する<!--]--></a></div><!----></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-a4b38bd6><span class="visually-hidden" id="doc-footer-aria-label" data-v-a4b38bd6>Pager</span><div class="pager" data-v-a4b38bd6><a class="VPLink link pager-link prev" href="/ja/api/mp_math/segment.html" data-v-a4b38bd6><!--[--><span class="desc" data-v-a4b38bd6>前のページ</span><span class="title" data-v-a4b38bd6>mbcp.mp_math.segment</span><!--]--></a></div><div class="pager" data-v-a4b38bd6><a class="VPLink link pager-link next" href="/ja/api/mp_math/vector.html" data-v-a4b38bd6><!--[--><span class="desc" data-v-a4b38bd6>次のページ</span><span class="title" data-v-a4b38bd6>mbcp.mp_math.vector</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-22f859ac data-v-e3ca6860><div class="container" data-v-e3ca6860><p class="message" data-v-e3ca6860><a href="https://vitepress.dev/">VitePress</a> で構築されたドキュメント | <a href="https://github.com/LiteyukiStudio/litedoc">litedoc</a> によって生成されたAPIリファレンス</p><p class="copyright" data-v-e3ca6860>Copyright (C) 2020-2024 SnowyKami. All Rights Reserved</p></div></footer><!--[--><!--]--></div></div>
<script>window.__VP_HASH_MAP__=JSON.parse("{\"api_api.md\":\"mzISWuiq\",\"api_index.md\":\"DSljii6t\",\"api_mp_math_angle.md\":\"3Na5IaYp\",\"api_mp_math_const.md\":\"O6cTulwX\",\"api_mp_math_equation.md\":\"z85zyCZL\",\"api_mp_math_function.md\":\"BhmJqpOo\",\"api_mp_math_index.md\":\"DHhPNV6R\",\"api_mp_math_line.md\":\"Dovi6bdM\",\"api_mp_math_mp_math.md\":\"mVabZTHd\",\"api_mp_math_mp_math_typing.md\":\"CEryCREV\",\"api_mp_math_plane.md\":\"Dv-GWbJg\",\"api_mp_math_point.md\":\"BvvrKTY8\",\"api_mp_math_segment.md\":\"_n__ViVt\",\"api_mp_math_utils.md\":\"kW3A-lG9\",\"api_mp_math_vector.md\":\"DvJcuPXW\",\"api_particle_index.md\":\"BxLVuqry\",\"api_particle_particle.md\":\"CioLG9Ab\",\"api_presets_index.md\":\"C7sBj6Q8\",\"api_presets_model_index.md\":\"F2zeh9P2\",\"api_presets_model_model.md\":\"BoocA59j\",\"api_presets_presets.md\":\"kIUJtfck\",\"demo_index.md\":\"CVAdlaFI\",\"en_api_api.md\":\"DFuvT6uG\",\"en_api_index.md\":\"29g4_ddH\",\"en_api_mp_math_angle.md\":\"09R7pxw_\",\"en_api_mp_math_const.md\":\"DjbxFoGO\",\"en_api_mp_math_equation.md\":\"DBXwIC0s\",\"en_api_mp_math_function.md\":\"nJ-E5W5r\",\"en_api_mp_math_index.md\":\"ypHGEnmb\",\"en_api_mp_math_line.md\":\"D0AfsxWD\",\"en_api_mp_math_mp_math.md\":\"5IisTIt3\",\"en_api_mp_math_mp_math_typing.md\":\"DWjztCj6\",\"en_api_mp_math_plane.md\":\"3xsZdWoR\",\"en_api_mp_math_point.md\":\"CxCgy181\",\"en_api_mp_math_segment.md\":\"BevquOvV\",\"en_api_mp_math_utils.md\":\"rVP-A71G\",\"en_api_mp_math_vector.md\":\"DMwD59YV\",\"en_api_particle_index.md\":\"NezC90nG\",\"en_api_particle_particle.md\":\"BTk7xB-d\",\"en_api_presets_index.md\":\"Clhg0YLX\",\"en_api_presets_model_index.md\":\"_hbR1U40\",\"en_api_presets_model_model.md\":\"B9FfcMgc\",\"en_api_presets_presets.md\":\"5pMosEdX\",\"en_guide_index.md\":\"C3kI8f8A\",\"en_index.md\":\"D5CddOW-\",\"en_refer_index.md\":\"Cq6GWi0V\",\"guide_index.md\":\"BVhQ0kPy\",\"index.md\":\"DJWBRkUz\",\"ja_api_api.md\":\"Bz39-sMD\",\"ja_api_index.md\":\"D2qTR3yI\",\"ja_api_mp_math_angle.md\":\"CAq1hHov\",\"ja_api_mp_math_const.md\":\"CACmM3Q4\",\"ja_api_mp_math_equation.md\":\"CwX1EUnA\",\"ja_api_mp_math_function.md\":\"BpyLWMmS\",\"ja_api_mp_math_index.md\":\"B_UDRWJp\",\"ja_api_mp_math_line.md\":\"BzytbSsM\",\"ja_api_mp_math_mp_math.md\":\"DGl-Yqoj\",\"ja_api_mp_math_mp_math_typing.md\":\"BANGfx9Q\",\"ja_api_mp_math_plane.md\":\"Bw6ecTDW\",\"ja_api_mp_math_point.md\":\"CFCWaCvm\",\"ja_api_mp_math_segment.md\":\"cuLLXTSO\",\"ja_api_mp_math_utils.md\":\"CrPKk6ui\",\"ja_api_mp_math_vector.md\":\"PFGJik39\",\"ja_api_particle_index.md\":\"SXvJHpqE\",\"ja_api_particle_particle.md\":\"DpDqAPA7\",\"ja_api_presets_index.md\":\"DrJ0aeZq\",\"ja_api_presets_model_index.md\":\"ub3RsBC9\",\"ja_api_presets_model_model.md\":\"Dw-6mfuk\",\"ja_api_presets_presets.md\":\"Bm4b0yEm\",\"ja_guide_index.md\":\"w1Tf2Adm\",\"ja_index.md\":\"DnsqZi7i\",\"ja_refer_index.md\":\"DamUscs8\",\"refer_function_curry.md\":\"D_oqRDd3\",\"refer_function_function.md\":\"Bi_82lIJ\",\"refer_index.md\":\"yFZW0kI4\",\"zht_api_api.md\":\"CeT7Da2J\",\"zht_api_index.md\":\"jP3pIyRV\",\"zht_api_mp_math_angle.md\":\"xBQ5jf2w\",\"zht_api_mp_math_const.md\":\"DhnGo46u\",\"zht_api_mp_math_equation.md\":\"CNqNdo8e\",\"zht_api_mp_math_function.md\":\"BYw-sqJL\",\"zht_api_mp_math_index.md\":\"C-ytwIT_\",\"zht_api_mp_math_line.md\":\"BKWlVJmv\",\"zht_api_mp_math_mp_math.md\":\"WAo96wsQ\",\"zht_api_mp_math_mp_math_typing.md\":\"2475K9x4\",\"zht_api_mp_math_plane.md\":\"Cbo0QRQD\",\"zht_api_mp_math_point.md\":\"Ci0RyJlm\",\"zht_api_mp_math_segment.md\":\"D_xbGo8n\",\"zht_api_mp_math_utils.md\":\"BsNVdUjt\",\"zht_api_mp_math_vector.md\":\"CelHQ_68\",\"zht_api_particle_index.md\":\"C8wv1sGB\",\"zht_api_particle_particle.md\":\"DLxDzJsb\",\"zht_api_presets_index.md\":\"CKWpXp08\",\"zht_api_presets_model_index.md\":\"a46BvX0I\",\"zht_api_presets_model_model.md\":\"C8PKDM2B\",\"zht_api_presets_presets.md\":\"nxuS_hT6\",\"zht_guide_index.md\":\"BNnMViC8\",\"zht_index.md\":\"CUR8-QXm\",\"zht_refer_index.md\":\"B7CQS2UW\"}");function deserializeFunctions(r){return Array.isArray(r)
</body>
</html>