csirmaz.openscad-py/doc/openscad_py/point.html
2024-12-01 15:52:02 +00:00

373 lines
20 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<meta name="generator" content="pdoc3 0.11.3">
<title>openscad_py.point API documentation</title>
<meta name="description" content="">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => {
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
hljs.highlightAll();
})</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>openscad_py.point</code></h1>
</header>
<section id="section-intro">
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="openscad_py.point.Point"><code class="flex name class">
<span>class <span class="ident">Point</span></span>
<span>(</span><span>coords)</span>
</code></dt>
<dd>
<div class="desc"><p>Represents a point or vector in arbitrary dimensions</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class Point:
&#34;&#34;&#34;Represents a point or vector in arbitrary dimensions&#34;&#34;&#34;
def __init__(self, coords):
self.c = np.array(coords, dtype=NP_TYPE)
@classmethod
def c(cls, coords: TUnion[list, &#39;Point&#39;]) -&gt; &#39;Point&#39;:
&#34;&#34;&#34;Ensure coords is an instance of Point (idempotent)&#34;&#34;&#34;
if isinstance(coords, Point):
return coords
return Point(coords)
def render(self) -&gt; str:
&#34;&#34;&#34;Render the object into OpenSCAD code&#34;&#34;&#34;
return &#34;[&#34; + (&#34;,&#34;.join([str(c) for c in self.c])) + &#34;]&#34;
def render_stl(self) -&gt; str:
return &#34; &#34;.join([str(c) for c in self.c])
def scale(self, x: float) -&gt; &#39;Point&#39;:
&#34;&#34;&#34;Scale the current vector/point by a scalar&#34;&#34;&#34;
return self.__class__(self.c * x)
def add(self, p: &#39;Point&#39;) -&gt; &#39;Point&#39;:
assert isinstance(p, Point)
assert self.dim() == p.dim()
return self.__class__(self.c + p.c)
def sub(self, p: &#39;Point&#39;) -&gt; &#39;Point&#39;:
assert isinstance(p, Point)
assert self.dim() == p.dim()
return self.__class__(self.c - p.c)
def dim(self) -&gt; int:
&#34;&#34;&#34;Return the number of dimensions&#34;&#34;&#34;
return self.c.shape[0]
def is_zero(self) -&gt; bool:
&#34;&#34;&#34;Return whether all coordinates are very close to 0&#34;&#34;&#34;
return np.all(np.abs(self.c) &lt; EPSILON)
def length(self) -&gt; float:
&#34;&#34;&#34;Return the length of the vector&#34;&#34;&#34;
return np.sqrt(np.square(self.c).sum())
def norm(self) -&gt; &#39;Point&#39;:
l = self.length()
if l == 0:
raise Exception(&#34;normalising 0 vector&#34;)
return self.__class__(self.c / self.length())
def dot(self, p: &#39;Point&#39;) -&gt; float:
&#34;&#34;&#34;Return the dot product&#34;&#34;&#34;
return np.dot(self.c, p.c)
def cross(self, p: &#39;Point&#39;) -&gt; &#39;Point&#39;:
&#34;&#34;&#34;Return the cross product&#34;&#34;&#34;
assert self.dim() == 3
assert p.dim() == 3
return Point([
self.c[1]*p.c[2] - self.c[2]*p.c[1],
self.c[2]*p.c[0] - self.c[0]*p.c[2],
self.c[0]*p.c[1] - self.c[1]*p.c[0]
])
def eq(self, p: &#39;Point&#39;) -&gt; bool:
return (self.c == p.c).all()
def lt(self, p: &#39;Point&#39;) -&gt; bool:
return (self.c &lt; p.c).all()
def le(self, p: &#39;Point&#39;) -&gt; bool:
return (self.c &lt;= p.c).all()
def gt(self, p: &#39;Point&#39;) -&gt; bool:
return (self.c &gt; p.c).all()
def ge(self, p: &#39;Point&#39;) -&gt; bool:
return (self.c &gt;= p.c).all()
def allclose(self, p: &#39;Point&#39;) -&gt; bool:
return self.c.shape == p.c.shape and np.allclose(self.c, p.c)
def angle(self, p: &#39;Point&#39;, mode: str = &#34;deg&#34;) -&gt; float:
&#34;&#34;&#34;Return the angle between two vectors in degrees or radians&#34;&#34;&#34;
r = self.dot(p)
r = r / self.length() / p.length()
r = math.acos(r)
if mode == &#34;rad&#34;:
return r
if mode == &#34;deg&#34;:
return r / math.pi * 180.
raise ValueError(&#34;Unknown mode&#34;)
def z_slope(self, mode: str = &#34;deg&#34;) -&gt; float:
&#34;&#34;&#34;Return the slope of a vector in degrees or radians&#34;&#34;&#34;
r = self.c[2] / self.length()
r = math.asin(r)
if mode == &#34;rad&#34;:
return r
if mode == &#34;deg&#34;:
return r / math.pi * 180.
raise ValueError(&#34;Unknown mode&#34;)
def rotate(self, coords, angle: float) -&gt; &#39;Point&#39;:
&#34;&#34;&#34;Rotate. coords is a list of 2 coordinate indices that we rotate&#34;&#34;&#34;
assert len(coords) == 2
ca, cb = coords
s = np.sin(angle / 180. * np.pi)
c = np.cos(angle / 180. * np.pi)
r = self.clone().reset_cache()
r.c[ca] = c * self.c[ca] + s * self.c[cb]
r.c[cb] = -s * self.c[ca] + c * self.c[cb]
return r
# Operator overloading
def __add__(self, other):
return self.add(other)
def __radd__(self, other):
assert isinstance(other, Point)
return other.add(self)
def __sub__(self, other):
return self.sub(other)
def __rsub__(self, other):
assert isinstance(other, Point)
return other.sub(self)
def __mul__(self, other):
return self.scale(other)
def __rmul__(self, other):
return self.scale(other)
def __neg__(self):
return self.scale(-1.)</code></pre>
</details>
<h3>Static methods</h3>
<dl>
<dt id="openscad_py.point.Point.c"><code class="name flex">
<span>def <span class="ident">c</span></span>(<span>coords: list | ForwardRef('<a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>')) > <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></span>
</code></dt>
<dd>
<div class="desc"><p>Ensure coords is an instance of Point (idempotent)</p></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="openscad_py.point.Point.add"><code class="name flex">
<span>def <span class="ident">add</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.allclose"><code class="name flex">
<span>def <span class="ident">allclose</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > bool</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.angle"><code class="name flex">
<span>def <span class="ident">angle</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>,<br>mode: str = 'deg') > float</span>
</code></dt>
<dd>
<div class="desc"><p>Return the angle between two vectors in degrees or radians</p></div>
</dd>
<dt id="openscad_py.point.Point.cross"><code class="name flex">
<span>def <span class="ident">cross</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></span>
</code></dt>
<dd>
<div class="desc"><p>Return the cross product</p></div>
</dd>
<dt id="openscad_py.point.Point.dim"><code class="name flex">
<span>def <span class="ident">dim</span></span>(<span>self) > int</span>
</code></dt>
<dd>
<div class="desc"><p>Return the number of dimensions</p></div>
</dd>
<dt id="openscad_py.point.Point.dot"><code class="name flex">
<span>def <span class="ident">dot</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > float</span>
</code></dt>
<dd>
<div class="desc"><p>Return the dot product</p></div>
</dd>
<dt id="openscad_py.point.Point.eq"><code class="name flex">
<span>def <span class="ident">eq</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > bool</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.ge"><code class="name flex">
<span>def <span class="ident">ge</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > bool</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.gt"><code class="name flex">
<span>def <span class="ident">gt</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > bool</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.is_zero"><code class="name flex">
<span>def <span class="ident">is_zero</span></span>(<span>self) > bool</span>
</code></dt>
<dd>
<div class="desc"><p>Return whether all coordinates are very close to 0</p></div>
</dd>
<dt id="openscad_py.point.Point.le"><code class="name flex">
<span>def <span class="ident">le</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > bool</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.length"><code class="name flex">
<span>def <span class="ident">length</span></span>(<span>self) > float</span>
</code></dt>
<dd>
<div class="desc"><p>Return the length of the vector</p></div>
</dd>
<dt id="openscad_py.point.Point.lt"><code class="name flex">
<span>def <span class="ident">lt</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > bool</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.norm"><code class="name flex">
<span>def <span class="ident">norm</span></span>(<span>self) > <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.render"><code class="name flex">
<span>def <span class="ident">render</span></span>(<span>self) > str</span>
</code></dt>
<dd>
<div class="desc"><p>Render the object into OpenSCAD code</p></div>
</dd>
<dt id="openscad_py.point.Point.render_stl"><code class="name flex">
<span>def <span class="ident">render_stl</span></span>(<span>self) > str</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.rotate"><code class="name flex">
<span>def <span class="ident">rotate</span></span>(<span>self, coords, angle: float) > <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></span>
</code></dt>
<dd>
<div class="desc"><p>Rotate. coords is a list of 2 coordinate indices that we rotate</p></div>
</dd>
<dt id="openscad_py.point.Point.scale"><code class="name flex">
<span>def <span class="ident">scale</span></span>(<span>self, x: float) > <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></span>
</code></dt>
<dd>
<div class="desc"><p>Scale the current vector/point by a scalar</p></div>
</dd>
<dt id="openscad_py.point.Point.sub"><code class="name flex">
<span>def <span class="ident">sub</span></span>(<span>self,<br>p: <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a>) > <a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="openscad_py.point.Point.z_slope"><code class="name flex">
<span>def <span class="ident">z_slope</span></span>(<span>self, mode: str = 'deg') > float</span>
</code></dt>
<dd>
<div class="desc"><p>Return the slope of a vector in degrees or radians</p></div>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="openscad_py" href="index.html">openscad_py</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="openscad_py.point.Point" href="#openscad_py.point.Point">Point</a></code></h4>
<ul class="two-column">
<li><code><a title="openscad_py.point.Point.add" href="#openscad_py.point.Point.add">add</a></code></li>
<li><code><a title="openscad_py.point.Point.allclose" href="#openscad_py.point.Point.allclose">allclose</a></code></li>
<li><code><a title="openscad_py.point.Point.angle" href="#openscad_py.point.Point.angle">angle</a></code></li>
<li><code><a title="openscad_py.point.Point.c" href="#openscad_py.point.Point.c">c</a></code></li>
<li><code><a title="openscad_py.point.Point.cross" href="#openscad_py.point.Point.cross">cross</a></code></li>
<li><code><a title="openscad_py.point.Point.dim" href="#openscad_py.point.Point.dim">dim</a></code></li>
<li><code><a title="openscad_py.point.Point.dot" href="#openscad_py.point.Point.dot">dot</a></code></li>
<li><code><a title="openscad_py.point.Point.eq" href="#openscad_py.point.Point.eq">eq</a></code></li>
<li><code><a title="openscad_py.point.Point.ge" href="#openscad_py.point.Point.ge">ge</a></code></li>
<li><code><a title="openscad_py.point.Point.gt" href="#openscad_py.point.Point.gt">gt</a></code></li>
<li><code><a title="openscad_py.point.Point.is_zero" href="#openscad_py.point.Point.is_zero">is_zero</a></code></li>
<li><code><a title="openscad_py.point.Point.le" href="#openscad_py.point.Point.le">le</a></code></li>
<li><code><a title="openscad_py.point.Point.length" href="#openscad_py.point.Point.length">length</a></code></li>
<li><code><a title="openscad_py.point.Point.lt" href="#openscad_py.point.Point.lt">lt</a></code></li>
<li><code><a title="openscad_py.point.Point.norm" href="#openscad_py.point.Point.norm">norm</a></code></li>
<li><code><a title="openscad_py.point.Point.render" href="#openscad_py.point.Point.render">render</a></code></li>
<li><code><a title="openscad_py.point.Point.render_stl" href="#openscad_py.point.Point.render_stl">render_stl</a></code></li>
<li><code><a title="openscad_py.point.Point.rotate" href="#openscad_py.point.Point.rotate">rotate</a></code></li>
<li><code><a title="openscad_py.point.Point.scale" href="#openscad_py.point.Point.scale">scale</a></code></li>
<li><code><a title="openscad_py.point.Point.sub" href="#openscad_py.point.Point.sub">sub</a></code></li>
<li><code><a title="openscad_py.point.Point.z_slope" href="#openscad_py.point.Point.z_slope">z_slope</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.3</a>.</p>
</footer>
</body>
</html>