<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Austin on Medium]]></title>
        <description><![CDATA[Stories by Austin on Medium]]></description>
        <link>https://medium.com/@austin9109?source=rss-2353a3e2e438------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lMB2D-O4rGBR8FK3_XKFlA.jpeg</url>
            <title>Stories by Austin on Medium</title>
            <link>https://medium.com/@austin9109?source=rss-2353a3e2e438------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:42:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@austin9109/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understand Unity GUI: Anchor and Pivot]]></title>
            <link>https://medium.com/@austin9109/understand-unity-gui-anchor-and-pivot-dcfe0ef7506e?source=rss-2353a3e2e438------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcfe0ef7506e</guid>
            <dc:creator><![CDATA[Austin]]></dc:creator>
            <pubDate>Sat, 20 Jul 2024 03:50:27 GMT</pubDate>
            <atom:updated>2024-07-20T03:50:27.144Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This is a series of articles aimed at providing readers with a clearer understanding of Unity usage techniques.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*j8hpS-m9roZrZoPGCbfCAQ.png" /></figure><h3>Introduction</h3><p>When developing with Unity, you will inevitably use Unity’s GUI toolbox to design an attractive interface for your app. To ensure that your application can smoothly achieve responsive functionality and maintain a comfortable layout, it is essential to understand how Unity controls the positioning of various UI elements. Today, let’s explore two of the most important properties in Unity GUI: Anchor and Pivot.</p><h3>Anchor</h3><p>The literal interpretation of “Anchor” is “Fix point.” From this perspective, it is used to maintain a fixed relationship. Before explaining the real meaning of Anchors, let’s first look at how Unity manage the Anchor properties, which will help understand the purpose behind the Anchor design.</p><p>In Unity’s Inspector on the right, the Anchor settings are divided into two parts: min and max.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*1jucs4MUnS8yLo_ePnN_nA.png" /></figure><p>A UI element has a total of four anchors, corresponding to the four corners of the rectangular element, with pairs for the horizontal and vertical directions. The anchor coordinates are defined relative to the width and height of the parent UI object(in the following, I will call parent UI object as background canvas), described in a proportional manner.</p><p>For example, when an anchor is at (0.5, 0.5), it means the anchor is located at the center of the background canvas. When the anchor is at (0.75, 1), it means it is located at the top edge, one-fourth of the way from the right side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*OzihVNnarSelUiPYGyC7eA.png" /><figcaption><strong>Description of Anchor Min (0.5, 0.5) and Anchor Max (0.75, 1)</strong></figcaption></figure><p>Since Unity’s coordinate system is described with the origin at the bottom-left corner, the <strong>bottom-left </strong>anchor corresponds to <strong>anchor min</strong>, and the <strong>top-right</strong> anchor corresponds to <strong>anchor max</strong>. Connecting these two points forms a rectangle, and the four corners of this rectangle represent the positions of the anchors.</p><h4>Effect of Anchor</h4><p>When the background canvas is resized, the relative position of the anchors within the canvas object remains unchanged. As shown in the image below, regardless of the size of the background canvas, the anchors maintain a consistent proportion in the horizontal direction. This is precisely where the name “anchor” comes from:</p><blockquote><strong><em>No matter how the parent UI object is resized, the anchors always remain fixed at the same proportional positions, just like a ship’s anchor.</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*soz8_IOp2P3htD8deLPPpw.gif" /><figcaption>Regardless of how the background canvas is resized, the anchors on the left and right sides always remain 25% away from the edges.</figcaption></figure><p>Since we already know that the relative positions of the anchors do not change with the resizing of the background canvas, let’s now look at how anchors affect the size of the UI elements themselves:</p><p>When Anchors <strong>do not overlap</strong>, Unity describes the <strong>size </strong>of the UI element in terms of the “<strong>relative distance” between the Anchors</strong>. In the other side, when Anchors <strong>overlap</strong>, Unity describes the <strong>size </strong>of the UI element using “<strong>fixed dimensions”</strong>.</p><p>For example, in the image above, if “Anchor Min” and “Anchor Max” are set to (0.25, 0) and (0.75, 0) respectively, the settings in the Inspector would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*3U32FxjI0W1grwhK7rElnQ.png" /></figure><ul><li><strong>“Left / Right” </strong>indicates the distance between the anchors on the left and right sides of the object.</li><li><strong>“Height” </strong>directly describes the height of the object.</li><li>Besides, since the <strong>height </strong>is fixed, the <strong>PosY </strong>is used to indicate the distance from the anchors.</li></ul><p>Since no matter how the background canvas is resized, the anchors maintain the set proportion with the parent object, this design approach is quite easy to understand:</p><ul><li>When anchors are “<strong>separated”</strong>, it means we want the UI element to “<strong>scale with the parent object”</strong>.</li><li>When anchors “<strong>overlap</strong>”, it means we want the size of the UI element to “<strong>remain fixed”</strong>, regardless of how the parent object is resized.</li></ul><blockquote>When arranging UI elements, we want the element to either scale with the background or maintain a fixed size and distance. This way, when the screen resolution changes, the UI element can adapt to the screen’s aspect ratio.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*KKugQVaXfMAr1eDCpGSG7Q.gif" /><figcaption>When the vertical anchors overlap, the distance between the UI element and the anchors remains consistent even when the parent UI object is resized.</figcaption></figure><h4>Summary</h4><ul><li>When the anchors are not overlapping, the UI element will adjust its size along with the resizing of the background canvas.</li><li>When the anchors overlap, the UI element maintains the same size regardless of how the background canvas is resized.</li></ul><h3>Pivot</h3><p>Next, we talking about “Pivot”. The plain explanation of Pivot is the “<strong>center point”</strong>, but I prefer to describe it as the “<strong>center point of the UI element’s coordinate system</strong>.” Any <strong>rotation</strong>, <strong>translation</strong>, or <strong>scaling </strong>is adjusted relative to the position of the Pivot.</p><p>As mentioned earlier, when anchors overlap, Unity positions the UI element on the canvas based on “<strong>relative distance</strong>”, which is the “<strong>distance between the Pivot and the Anchor:</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*NO0NuTsd5Uxx0YJjlPiT-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*3FgreghJaVXB_78ivcaneQ.png" /><figcaption>The Pivot is located at the center of the UI, and its distance from the Anchor is half the width of the canvas (with the canvas size being 1920 x 1080).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*B2NZpijflwXIBZKsXTMNjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*-I8IJBpT-d_etJY271zRcw.png" /><figcaption>If the Pivot is located at the bottom of the UI, the distance between the Pivot and the Anchor is equal to half the canvas width minus half the UI width.</figcaption></figure><blockquote>Rotations, size, and scale modifications occur around the pivot so the position of the pivot affects the outcome of a rotation, resizing, or scaling.</blockquote><h3>Bonus: Local Position and Anchor Position</h3><p>Finally, let’s look at another two properties of RectTransform that can be obtained from script: LocalPosition and AnchorPosition</p><ul><li>Local Position: The relative position between the bakground canvas Pivot and the UI element Pivot (<strong>the distance between the two coordinate systems</strong>).</li><li>Anchor Position: The relative position between the Pivot and the center of the Anchor rectangle (<strong>the distance between the UI origin and the Anchor center</strong>).</li></ul><h3>Summary</h3><ul><li><strong>Anchor</strong>: Affects how the UI element scales and positions relative to the background canvas, allowing the element to adapt to changes (<strong>element responsiveness</strong>).</li><li><strong>Pivot</strong>: Affects the <strong>rotation</strong>, <strong>translation</strong>, and <strong>scaling </strong>of the UI element itself.</li></ul><p>In this article, we explored the design principles of Anchor and Pivot, and how they affect the layout of UI elements within the Unity canvas. In the next article, we will dive deeper into other GUI techniques and tips!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcfe0ef7506e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Unity Camp] 如何在 Unity 中高效地使用 Scriptable Object]]></title>
            <link>https://medium.com/@austin9109/unity-camp-%E5%A6%82%E4%BD%95%E5%9C%A8-unity-%E4%B8%AD%E9%AB%98%E6%95%88%E5%9C%B0%E4%BD%BF%E7%94%A8-scriptable-object-bbb6fd248cdd?source=rss-2353a3e2e438------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbb6fd248cdd</guid>
            <dc:creator><![CDATA[Austin]]></dc:creator>
            <pubDate>Mon, 22 May 2023 16:51:56 GMT</pubDate>
            <atom:updated>2023-05-22T16:51:56.807Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*r50pWqdVNidqMag8Y5SWbQ.jpeg" /></figure><h4>前言</h4><p>在使用 Unity 開發遊戲的過程中，一定或多或少的聽過 Scriptable Object 一詞，他是什麼? 相信很多人已經知道，但你知道該怎麼進一步的將 Scriptable Object 有效利用於當前進行的專案中嗎? 今天就讓我們一起來挖掘他背後所潛藏的潛力，以及它適合用於遊戲開發中的哪些領域。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*d9iKm-DvssDUauyhjQhiSA.jpeg" /><figcaption>學習如何透過 Scriptable Object 使程式碼耦合性降低，提高內聚力也是使用 Unity 做為開發工具時重要的一環</figcaption></figure><h4>什麼是 Scriptable Object ?</h4><p>有些 Unity 經驗的小夥伴一定有遇過下面幾個令人頭疼的問題:</p><ol><li>當編輯器進入遊戲模式之後，<strong>任何在 Inspector 中修改過的數值</strong>在結束 Play Mode 後都會自動復原 (喪失更改內容)</li><li>已經有關於遊戲內容的想法，並且能給出具體數值，但是只能將資料 key 在 Excel 或是 Json 中，再透過其他手段將這些資料匯入到 Unity 中</li><li>想要將調整過後的 GameObject 當作資源文件儲存起來，只能以 Prefab 的方式儲存在專案中</li></ol><p>第一個問題可以複製 Component 大法或是插件 (<a href="https://forum.unity.com/threads/play-mode-save.955539/">Play Mode Save</a>) 來達成，但都不是說非常有效解決問題的方式; 第二、三個問題追本溯源是要解決在 Unity 中實現資料儲存的問題，只是現存方法要嘛有某部分的缺陷，要嘛就是要再搭配額外工具或流程才可以實現。為了解決這些問題，<strong> Scriptable Object 誕生了!</strong></p><p>在 Unity 中 Scriptable Object 是一種非常有用的資料類型，它是一種可編輯物件，可以做為資源儲存在專案中，用於保存資料、設定參數、實作遊戲事件和其他需要序列化的資料。你可以把他想像成一份<strong>存放在本地端的資料庫</strong>，可以儲存可以存儲各種類型的資料，例如：音效、圖片、文本、字型、材質、Prefab 等等。最重要的是，Scriptable Object 與 Unity Editor 有良好的適配性，你可以直接打開 Editor 對其屬性做編輯、調整。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*T6AErnCEQosSLL2cWqkIvA.jpeg" /><figcaption>在 Inspector 中修改 Scriptable Object 的內容</figcaption></figure><h4>Scriptable Object 的特點</h4><p>在講解 Scriptable Object 的具體應用前，先介紹一下他的特點，有助於理解為什麼要使用 Scriptable Object 來解決問題:</p><ol><li>簡單易用</li></ol><p>創立 Scriptable Object 的方式很簡單，撰寫繼承至 <strong>Scriptable Object</strong> 物件後的類別，並將之<strong>實例化</strong>後就可以得到數據文件。如同 Monobehaviour 可以非常簡單地創建和使用，開發者只需要繼承 ScriptableObject 類別，並實現自己需要的資料和函數即可。Scriptable Object 非常容易被序列化和儲存，因此開發者可以方便地修改其數值和屬性。</p><p>2. 可重用性高</p><p>Scriptable Object 中的資源可以在遊戲開發過程中被重複使用，開發者可以通過修改 Scriptable Object 中的數值，來修改遊戲中的資源。這樣可以大大提高開發效率，減少資源重複使用帶來的問題。下面我們更具體的例子來說明達成減少資源復用的具體方法。</p><p>3. 易於擴展</p><p>Scriptable Object 是一個非常靈活的資料類型，可以很容易地進行擴展。開發者可以根據自己的需求，自定義屬性和方法，以滿足自己的需求。此外，由於 Scriptable Object 可以被繼承，開發者可以建立一個 Scriptable Object 的基類，然後通過繼承來創建不同類型的 Scriptable Object。</p><h4>Scriptable Object 使用上的注意事項</h4><p>雖然 Scriptable Object 在 Unity 遊戲開發中非常有用，但是在使用時也需要注意以下幾點：</p><ol><li>生命週期</li></ol><p>Scriptable Object 在遊戲運行時會被 Unity 引擎當做單例來處理，因此它的生命週期會比較長。在設計 Scriptable Object 時，需要考慮到它在遊戲運行時的生命週期，避免出現不必要的資源浪費。</p><p>2. 統一的資源管理</p><p>由於 Scriptable Object 可以被多個物件引用和修改，因此在使用時需要注意資源的管理。開發者需要確保在 Scriptable Object 被刪除時，它所引用的資源也能夠被正確地釋放。</p><p>3. Scriptable Object 的設計原則</p><p>在設計 Scriptable Object 時，需要考慮到其設計原則。開發者需要確保其設計符合 SOLID 原則和其他軟件設計原則，以確保其可維護性和可擴展性。</p><h4>Scriptable Object 的主要使用</h4><p>根據個人經驗，適合使用 Scriptable Object 的場合主要有三個:</p><p><strong>定義遊戲內的設定資料</strong></p><p>如同前面講述過的，Scriptable Object 一開始被設計的目的就是為了在 Unity 裡面可以實驗更直觀的儲存資料方式。設計遊戲內容可以用 Excel、Json 等工具來填寫數據，但這樣做還需要自行搭建配套措施匯入來自外部的定義資源。使用 Scriptable Object 可以直接在 Unity 中透過 Inspector 調整屬性內容，當 Scriptable Object 引用到其他資源素材時也可以直接進行配置，而非像填寫外部文件般需要定義資源的名稱、統一存放資料夾等操作等等。</p><p>此外，利用 Scriptable Object 定義遊戲數據，可以更輕易地達成數據分離的目的，讓 Monobehaviour 專注於遊戲物件行為的設計上，而 Scriptable Object 則用數據驅動 Monobehaviour 表現出不同的行為。搭配上在<strong>運行遊戲時修改過的內容即使在離開遊戲模式後其內容也會被保存下來</strong>此一特性，可以幫助開發者在遊戲開發過程中更加方便地管理遊戲內的資源，並且大幅提高開發效率。</p><p><strong>基於 Model-View-Controller 設計模式的資料容器</strong></p><p>數據驅動的設計方式可以帶來更易維護的架構，我們可以將運行期間的數據儲存在 Monobehaviour 本身，Monobehaviour 被修改過的內容在離開遊戲後就會被還原，此時 Scriptable Object 就很適合用來做為儲存容器，這邊指的是運行期間資料儲存的實例。例如當前場景中有若干物件都需要參照玩家角色的血量。</p><p><strong>減少 Memory 的複用</strong></p><p>在設計過程中，我們往往會儲存許多預制件 (Prefab)，會在後續的使用中實例化他們。假設今天有個遊戲預制件叫做 Bullet ，他的數據內容如下:</p><pre>public class Bullet : Monobehaviour<br>{<br>    public float Damage;<br>    public float Speed;<br>}</pre><p>這邊 Damage、Speed 是該子彈遊戲物件的設定數據。當 Bullet 在運行過程中被實例化時，每個被創立的子彈都會含有 Damage、Speed 兩個資料儲存空間，因為<strong>實例化 Monobehaviour 是完全複製，</strong>若是這些屬性在後續都不會被變動到便造成了記憶體資源的浪費<strong>。</strong>使用 Scriptable Object 可以改善記憶體複用的現象:</p><pre>public class BulletData : ScriptableOjbect<br>{<br>    public float Damage;<br>    public float Speed;<br>}<br><br><br>public class Bullet : Monobehaviour<br>{<br>    public BulletData bulletData;<br>}</pre><p>如此一來，所有被實例化的子彈物件所參照的物件都是同一份 BulletData 實例，因此可大幅降低複用現象。</p><h4>額外補充</h4><p>Scriptable Object 在開始運行後會被以 Singleton 的方式當作單一實例載入至引擎中，此處 Bullet 所參照並非是儲存在硬碟中的資源檔案，而是被載入過後的單一 BulletData 實例。</p><h4>總結</h4><p>Scriptable Object 是 Unity 遊戲開發中非常有用的一種資料類型，他有著<strong>編輯模式下數據永久保存</strong>、<strong>跨場景維持數據、可擴充性高</strong>以及<strong>資料複用</strong>等特點，適合用於配置遊戲中的數據、做為降低元件之間耦合性的數據容器、以及降低記憶體複用等具體應用。那今天的分享就到這邊啦~未來有機會的話還會與大家繼續分享其他使用 Scriptable Object 的有趣案例 !</p><h4>參考文獻</h4><p><a href="https://unity.com/how-to/architect-game-code-scriptable-objects">https://unity.com/how-to/architect-game-code-scriptable-objects</a></p><p><a href="https://gamedevbeginner.com/scriptable-objects-in-unity/">https://gamedevbeginner.com/scriptable-objects-in-unity/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbb6fd248cdd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[演算法基本概念 : Communicate within Algorithm]]></title>
            <link>https://medium.com/austin-yang/%E6%BC%94%E7%AE%97%E6%B3%95%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5-communicate-within-algorithm-18ceff5f861?source=rss-2353a3e2e438------2</link>
            <guid isPermaLink="false">https://medium.com/p/18ceff5f861</guid>
            <dc:creator><![CDATA[Austin]]></dc:creator>
            <pubDate>Tue, 25 Apr 2023 05:05:15 GMT</pubDate>
            <atom:updated>2023-04-25T05:05:15.555Z</atom:updated>
            <content:encoded><![CDATA[<h3>演算法基本概念 : Communicate within Algorithm</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYPyb68fNUbaQmzmLmEQbQ.png" /></figure><p><strong>前言</strong></p><p>這篇文章是我在修讀 MIT 的 <a href="https://www.youtube.com/watch?v=ZA-tUyM_y7s&amp;list=PLUl4u3cNGP63EdVPNLG3ToM6LaEUuStEY&amp;index=1">Introduction to Algorithm</a> 後所節錄下來的學習心得，主要是想記錄那些我們在討倫演算法時會常用到的基本觀念，瞭解這些內容可以幫助我們更進一步的與他人有溝通上的一致性。</p><p><strong>Big O : Asymptotic Notation (漸進符號)</strong></p><p>前面有提到，在提出演算法時我們最關注的兩個面向分別是<strong>正確性</strong>還<strong>有效率(或正確地來說執行時間)</strong>。正確性可以透過數學歸納法或是其他論證方法等來驗證，有效性則可以透過兩種方法來進行驗證:</p><ol><li>撰寫程式執行並測量時間</li><li>用看的，觀察執行時間隨資料擴增的變化趨勢</li></ol><p>測量執行時間雖然是最直接的方法，但其結果會隨機器之間不同性能而有所影響，因此在討論執行效率時較常用演算法的<strong>計算次數</strong>來辨識，而計算次數又受輸入參數的規模大小有所影響，因而有了<strong>漸進表示法</strong>的引入。</p><p><strong>什麼是漸進符號 (Asymptotic Notation) ?</strong></p><p>根據維基百科的定義:</p><blockquote>是用於描述<a href="https://zh.wikipedia.org/wiki/%E5%87%BD%E6%95%B0">函式</a><a href="https://zh.wikipedia.org/wiki/%E6%B8%90%E8%BF%91%E5%88%86%E6%9E%90">漸近行為</a>的<a href="https://zh.wikipedia.org/wiki/%E6%95%B0%E5%AD%A6">數學</a>符號。更確切地說，它是用另一個（通常更簡單的）函式來描述一個函式<a href="https://zh.wikipedia.org/wiki/%E6%95%B0%E9%87%8F%E7%BA%A7">數量級</a>的<strong>漸近上界</strong>。</blockquote><p>白話的來說，漸進表示法旨在探討當輸入的資料規模變得越來越大，演算法的計算行為是否也會跟著增加? 增加的幅度變化又是如何? 因此漸進表示法不等於演算法確切的執行時間。</p><p>舉例來說，若對任意輸入的資料大小進行某一操作能以固定的計算次數完成 (Constant Time)，則當輸入的資料非常大時演算法也可以同樣的計算次數完成，這就是一個具有極佳效率的方法。</p><p><strong>資料結構 </strong>(Data Structure) <strong>與介面 (Interface)</strong></p><p>資料結構是一種儲存動態資料的方法，並且滿足一系列共通的資料操作方法。</p><p>介面是一組對資料操作方法的集合。可以說介面定義了那些操作是可行的 (問題)，而資料結構定義了如何實踐這些操作方法 (問題的答案)。</p><p>同一個介面可以用不同資料結構的方式來實踐。</p><p><strong>平攤分析 (Armotized Analysis)</strong></p><p>攤銷分析是一種分析算法時間複雜度的方法，通常用於評估一個算法的平均性能。根據<a href="https://en.wikipedia.org/wiki/Amortized_analysis">維基百科</a>的定義:</p><blockquote>The motivation for amortized analysis is that looking at the worst-case run time can be too pessimistic. Instead, amortized analysis averages the running times of operations in a sequence over that sequence.</blockquote><p>大意是說，演算法中某項操作在當下可能不是很具效率 (如: 擴增 N 筆資料 所需的時間複雜度為 O(N) )，但是在對後續操作中能提升其計算效率中，從總體的角度來看時間複雜度反而是有所下降 (插入/刪除資料 Complexity 變為 O(1) )，即算法的每個操作的時間複雜度不一定相同，但在長時間內，每個操作的代價的平均值應該是穩定的。</p><p>平攤分析有三種方法:</p><ul><li>聚攏法 (Aggregate method)</li><li>償還法 (Accounting Method)</li><li>位能法 (Potential Method)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18ceff5f861" width="1" height="1" alt=""><hr><p><a href="https://medium.com/austin-yang/%E6%BC%94%E7%AE%97%E6%B3%95%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5-communicate-within-algorithm-18ceff5f861">演算法基本概念 : Communicate within Algorithm</a> was originally published in <a href="https://medium.com/austin-yang">CS University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[詳解 Stack 與 Heap 之間的特性與差異]]></title>
            <link>https://medium.com/austin-yang/cs-university-%E8%A9%B3%E8%A7%A3-stack-%E8%88%87-heap-%E4%B9%8B%E9%96%93%E7%9A%84%E7%89%B9%E6%80%A7%E8%88%87%E5%B7%AE%E7%95%B0-cce4d7e4dcf?source=rss-2353a3e2e438------2</link>
            <guid isPermaLink="false">https://medium.com/p/cce4d7e4dcf</guid>
            <dc:creator><![CDATA[Austin]]></dc:creator>
            <pubDate>Wed, 19 Apr 2023 08:24:03 GMT</pubDate>
            <atom:updated>2023-04-21T02:18:51.552Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>前前言</strong></p><p>最近由於工作上的需要，也出自於想重新審視自己在軟體工程師這條路上所欠缺的能力，因此計畫打算參照 John Washam 所撰寫的著名文章: <a href="https://github.com/jwasham/coding-interview-university">Coding Interview University</a> 裡面的內容來一步步研讀與核對自己不熟悉的地方，期許自己在經過此次的計畫後能更具備一位成熟工程師所需要的知識與技巧。</p><p><strong>前言</strong></p><p>堆(Heap)與棧(Stack)為軟體開發人員需要具備的基礎觀念之一，這兩個名詞在不同的背景下有不同的代表意思:</p><p>在程式內存的討論中: 堆與棧表示了兩種不同的內存管理方式<br>在資料結構的討論中: 堆與棧表示了兩種不同的資料儲存結構</p><p>即便兩者的代表意思不同，但其背後的原理與概念大致相同，因此這邊介紹會直接以程式記憶體的角度做切入。</p><p>先來看一張程式啟動時記憶體的分配狀態圖:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*fduC6kF7R1zQy2NK_p-Nxw.png" /><figcaption>程式記憶體架構圖</figcaption></figure><p><strong>資料結構中的棧</strong></p><p>Stack 是一種只允許在儲存容器的一端進行插入和删除的動作，稱為棧頂 (Stack Top)，操作採取先進後出(First in-Last out，FILO)的資料堆疊儲存方式。當把新元素放到棧頂元素的上面，使之成為新的棧頂元素稱作進棧、入棧或壓棧（Push）; 把棧頂元素删除，使其相鄰的元素成為新的棧頂元素稱作出棧或退棧（Pop )。</p><p><strong>程式內存中的棧</strong></p><p>Stack 由作業系統自動管理，用於儲存程式中 Function 的呼叫、傳入參數以及所有區域變數，採取先進後出的方式依序堆疊放置在棧內，相鄰變數對應的地址間不會存在其它变量，並且其數據在生命週期結束後由系統回收取出。另外，Stack在記憶體位置上的生長方向是由高往低生長，越後面進入 Stack 中的變量其對應的記憶體位址也越小。</p><p>每個程式所分配到的 Stack 大小在編譯完成就固定了，若是在執行的過程中要塞入 Stack 中的數據大小大於 Stack 中所剩餘的儲存空間，此時就會爆出記憶體空間不足。 (Stack Overflow!)</p><p><strong>資料結構中的堆</strong></p><p>堆是一種樹形資料結構的通稱，是特化過的的<strong>完全二分法樹</strong>，其滿足樹中所有節點的值總是不大於（或不小於）父節點的值，此特性又稱作<strong>堆序性</strong>。在堆中根節點是最大（或最小）節点。擁有<strong>最小根節點</strong>稱之為<strong>小根堆</strong>，<strong>最大根節點</strong>稱之為<strong>大根堆</strong>。另外堆的左右子節點没有大小順序的差別。對堆中任意節點的插入、刪除以及建立都要滿足此一堆序性。</p><p><strong>程式內存中的堆</strong></p><p>Heap 用於儲存程式運行期間動態分配的記憶體區域，由程式人員分配與釋放，可以適應不同大小和數量的資料。Heap 在可分配的空間大小上比其 Stack 來的大上許多，使用上也較彈性。</p><p>但是，它也存在一些缺點。由於 heap 是手動管理的，必須確保每個分配的內存塊都被正確地釋放，否則就會產生內存泄漏（memory leak），這會導致系統資源的浪費和性能問題，如果開發人員沒有正當的回收使用到的 Heap 區域記憶體的話會直到程式結束執行時由作業系統回收。</p><p>此外，請求 heap 記憶體區塊時時需要與作業系統溝通，因此速度會比 stack 來的較慢。另外，由於 heap 是透過上述的特化二分樹來儲存，從作業系統中閒置的記憶體區塊分割出來記憶體區段會掛在相對應的節點上，因此申請的記憶體空間在地址上不一定是連續的，並且其記憶體位址生長方向是由低往到高生長，但後進入的變數位址不一定大於先進入的變數位址(呼應前面提到的不連續性)。</p><p><strong>總結</strong></p><ul><li>記憶體位址生長方向: Stack 由高到低、Heap 由低到高</li><li>請求速度: Stack 較快、Heap 較慢</li><li>空間大小: Stack 較小、Heap 較大</li><li>分配方式: Stack 由系統自動發放、Heap 由程式人員分配釋放</li><li>數據結構: Stack 是先進後出、Heap 是特化二分樹</li></ul><p>希望在看完上述內容後可以快速複習與更加深 Stack 與 Heap 之間的特性與差異之處。</p><p><strong>補充: C++ 中的 Heap 與 Stack</strong></p><p>C++ 的語言概念中其實並沒有 Heap 或 Stack 之類的概念，相反地是使用資料的 Storage Behaviour 來區分，如 automatic storage、 dynamic storage、static storage and thread local storage. 每個 storage 依其實現方式再來區分其資料儲存於哪一區。</p><p><strong>參考資料</strong></p><p><a href="https://www.geeksforgeeks.org/memory-layout-of-c-program/">GeeksforGeeks</a><br><a href="https://blog.csdn.net/aabbccas/article/details/127739109?spm=1001.2101.3001.6650.10&amp;utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-10-127739109-blog-80849966.235%5Ev29%5Epc_relevant_default_base3&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-10-127739109-blog-80849966.235%5Ev29%5Epc_relevant_default_base3&amp;utm_relevant_index=14">CSDN</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cce4d7e4dcf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/austin-yang/cs-university-%E8%A9%B3%E8%A7%A3-stack-%E8%88%87-heap-%E4%B9%8B%E9%96%93%E7%9A%84%E7%89%B9%E6%80%A7%E8%88%87%E5%B7%AE%E7%95%B0-cce4d7e4dcf">詳解 Stack 與 Heap 之間的特性與差異</a> was originally published in <a href="https://medium.com/austin-yang">CS University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[碩班生活筆記--PC Based 伺服馬達配線實作]]></title>
            <link>https://medium.com/robotics-science/%E7%A2%A9%E7%8F%AD%E7%94%9F%E6%B4%BB%E7%AD%86%E8%A8%98-pc-based-%E4%BC%BA%E6%9C%8D%E9%A6%AC%E9%81%94%E9%85%8D%E7%B7%9A%E5%AF%A6%E4%BD%9C-657010d25f2e?source=rss-2353a3e2e438------2</link>
            <guid isPermaLink="false">https://medium.com/p/657010d25f2e</guid>
            <dc:creator><![CDATA[Austin]]></dc:creator>
            <pubDate>Tue, 18 Aug 2020 06:27:39 GMT</pubDate>
            <atom:updated>2023-04-21T02:28:42.937Z</atom:updated>
            <content:encoded><![CDATA[<h3>PC Based 伺服馬達配線實作</h3><blockquote><em>前一陣子經歷過忙碌到爆炸的七月(準備口試資料、製作投影片、南北兩地跑找工作)才發現到應該要將自己的經歷記錄下來才能夠拿來給自己做為日後的審視作用，因此趁著現在要展開軍旅生涯的空檔前好好記錄一下在碩士班就讀的兩年期間所接觸到的點點滴滴，部分內容也可以供與實驗室學弟妹作為筆記參考，或是日後自己想要接一台機械手臂來玩玩的時候可以回憶一下XD</em></blockquote><h3>伺服驅動馬達(Servo Motor)與他的小夥伴</h3><p>此次要實作的是的<strong>交流伺服馬達的配線</strong>，從上層的<strong>使用者電腦、運動控制軸卡</strong>，到下層的<strong>伺服馬達與驅動器</strong>，自行配線完成整套系統的串接，利用跳線串接運動控制軸卡與電子馬達之間的功能，使得操作者可以藉由電腦端下達指令驅動馬達運轉，並經由編碼器讀回馬達的轉動角度進行觀看，形成一個完整的伺服控制系統。過程中主要會使用到下列配件:</p><ol><li>Windows 7 作業系統的桌上型電腦</li><li>工研院所開發之運動控制軸卡</li><li>台達開發之馬達及驅動器</li><li>軸卡轉接板與驅動器轉接板</li><li>兩顆電子開關</li><li>110V與24V電源供應器</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eezU7UUdjefvCRn7DIoXag.jpeg" /><figcaption>軸卡轉接板</figcaption></figure><h3><strong>使各個小夥伴待在正確的崗位</strong></h3><p><strong>1. 將要配接的各項元件安置在一塊</strong></p><p>主要按照下列順序串接各個元件:</p><p>電腦 + 軸卡 ( PCI匯流排，如果裝置驗證沒過的話要先去裝置管理員設定裝置的安全驗證) -&gt; 100 Pin 線 -&gt; 軸卡轉接板 -&gt; 50PIN線 -&gt; 驅動器 -&gt; 馬達+減速機</p><ul><li>工研院開發的運動控制軸卡最多可支持八軸同動，不過在不上電的情況下軸卡最多只能控制六軸，如果想要開啟第七、第八軸的控制功能需要在額外供電給軸卡轉接板(電源指示燈會亮)。</li><li>特別注意，由於軸卡是採用送出電壓電流形式的命令(+10V~-10V)供與驅動器輸入，因此在接跳線前須要先拿三用電表檢查軸卡的電壓準位是否在0V，否則的話驅動器會一直接受到錯誤的命令。</li></ul><p><strong>2. 選擇要採用的控制模式</strong></p><p>下一步是根據任務目標考慮馬達要採用的控制形式(位置、速度、扭矩模式)，三種模式之間的差別以及優缺點網上有很多資料，</p><ul><li>在低速運行的狀態下有沒有針對系統動態進行補償可能看不出來太大的差別，但是若是機器運轉的速度相當高速，光是靠PID或是運動學的控制方法的話是沒辦法獲得較好的結果的(追蹤誤差)</li><li>由於實驗室已經發展出相當成熟的動態建模方法，能夠針對機器人的動態進行補償以及控制，因此此處是採用力矩控制的配線模式。</li></ul><p><strong>3. 使用跳線串接各個功能</strong></p><p>每一種控制模式的接線方式都有小小的不同，在手冊上可以查找到不同模式下各個功能對應到轉接板上的腳位，再利用跳線將軸卡轉接板與驅動器轉接板所互相對應的腳位對接。在扭矩控制模式下會需要對接以下幾種功能:</p><ol><li>DAC 、ADC</li><li>三相電壓電流</li><li>緊急開關 (剎車系統)</li><li>伺服開關 (Servo On)</li></ol><ul><li>剎車與 Servo On 的電子開關連接對應到驅動器轉接板左方的額外功能列，需要另外供與外接電壓 ( 9V ) 確保驅動器轉接板上的緊急開關與 Servo On 功能可以運轉。</li><li>Servo On 信號可以由電腦端送出，也可以藉由外接開關啟動。</li><li>驅動器也需額外供與 110V 的電壓(根據型號有所不同)。</li></ul><p>完成所有的配線項目後，即可藉由電腦端下達指令，觀看馬達的轉動方式是否正確。</p><h3><strong>後記</strong></h3><blockquote>第一次接觸到馬達的整套配線還是覺得蠻新穎的，之前都是使用別人已經接好的裝置，只要照著正確使用就可以，另外接到後面會發現跳線超多條，常常打結打在一起，要怎麼接的好看同時也易於維護又是另一門學問了，接完整套系統之後用電腦KEY進命令，看著馬達隨著開始正常運轉起來會有種莫名的成就感 👌</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=657010d25f2e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/robotics-science/%E7%A2%A9%E7%8F%AD%E7%94%9F%E6%B4%BB%E7%AD%86%E8%A8%98-pc-based-%E4%BC%BA%E6%9C%8D%E9%A6%AC%E9%81%94%E9%85%8D%E7%B7%9A%E5%AF%A6%E4%BD%9C-657010d25f2e">碩班生活筆記--PC Based 伺服馬達配線實作</a> was originally published in <a href="https://medium.com/robotics-science">Robotics Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>