欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MikTex的使用

程序员文章站 2023-12-25 11:05:57
...
  1. 首先下载 MikTex https://miktex.org/download MikTex
  2. TexWork的使用
    如下是包括了中文注释的算法实现
    有关Tex后缀文件中宏块的使用,以及算法中常见的运算符以及数学符号表达均可以参考textmaker中的表达。
\documentclass[11pt]{article}
\usepackage{CJK}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{amsmath}

\floatname{algorithm}{算法}
\renewcommand{\algorithmicrequire}{\textbf{输入:}}
\renewcommand{\algorithmicensure}{\textbf{输出:}}

\begin{document}
\begin{CJK*}{UTF8}{gkai}
    \begin{algorithm}
        \caption{用归并排序求逆序数}
        \begin{algorithmic}[1] %每行显示行号
            \Require $Array$数组,$n$数组大小
            \Ensure 逆序数
            \Function {MergerSort}{$Array, left, right$}
                \State $result \gets 0$
                \If {$left < right$}
                    \State $middle \gets (left + right) / 2$
                    \State $result \gets result +$ \Call{MergerSort}{$Array, left, middle$}
                    \State $result \gets result +$ \Call{MergerSort}{$Array, middle, right$}
                    \State $result \gets result +$ \Call{Merger}{$Array,left,middle,right$}
                \EndIf
                \State \Return{$result$}
            \EndFunction
            \State
            \Function{Merger}{$Array, left, middle, right$}
                \State $i\gets left$
                \State $j\gets middle$
                \State $k\gets 0$
                \State $result \gets 0$
                \While{$i<middle$ \textbf{and} $j<right$}
                    \If{$Array[i]<Array[j]$}
                        \State $B[k++]\gets Array[i++]$
                    \Else
                        \State $B[k++] \gets Array[j++]$
                        \State $result \gets result + (middle - i)$
                    \EndIf
                \EndWhile
                \While{$i<middle$}
                    \State $B[k++] \gets Array[i++]$
                \EndWhile
                \While{$j<right$}
                    \State $B[k++] \gets Array[j++]$
                \EndWhile
                \For{$i = 0 \to k-1$}
                    \State $Array[left + i] \gets B[i]$
                \EndFor
                \State \Return{$result$}
            \EndFunction
        \end{algorithmic}
    \end{algorithm}
\end{CJK*}
\end{document}

如下为根据上述表达更改后算法表达

\documentclass[11pt]{article}
\usepackage{CJK}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{amsmath}

\floatname{algorithm}{算法}
\renewcommand{\algorithmicrequire}{\textbf{输入:}}
\renewcommand{\algorithmicensure}{\textbf{输出:}}

\begin{document}
\begin{CJK*}{UTF8}{gkai}
    \begin{algorithm}
        \caption{轴类零件几何特征提取}
        \begin{algorithmic}[1] %每行显示行号
            \Require $part$  零件几何模型 ;$S$  面集合
            \Require $S_{m}$  加工面图节点集合 ;$FeatureTag$  包含几何信息特征类 
            \Require $CFeatureList$  特征链表   $Graph$  扩展属性邻接图
            \Function {ShaftPart}{$part$}  
                \State $Graph \; pGraph_{1},pGraph_{2}$       
                \State $S=\emptyset$,$S_{m}=\emptyset$ 
                \State $FeatureTag\;Tag=\emptyset$ 
					\State $CFeatureList\;Featurelist=\emptyset$ 
                \ForAll  {$f_{i}  \in  part.faces$ }    \quad零件面集合遍历
                    \If {$f_{i} \;is\; End\; face\;of\;Shaft $}    \quad如果是轴端面则标记为端面特征
                     \State  $mark\;f_{i}\;as\;End\;face$       
                     \State $S= S \cup f_{i}$         \quad得到面集合
                    \EndIf
                \EndFor                  
                \State $pGraph_{1}=InitializeGraph(S)$      \quad 由B-rep结构生成邻接图
                \ForAll {$f_{i} \;in\; S$}
                   \If {$f_{i}\;is\;machining base face$}
                     \State $S_{m}= S_{m} \cup f_{i}$   \quad 加工面图节点集合
                   \EndIf
                \EndFor
                \ForAll {$f_{k}\in S_{m}$} 
                  \If {$f_{k} \;compose \;MMCSG$}       \quad 满足加工面最小条件子图  
                     \State $FeatureTag\;Tag_{i}=CreateTag(f_{k})$     \quad 创建几何特征体
                     \State $Tag=Tag\cup Tag_{i}$                       
                     \State $pGraph_{2}=pGraph_{1}-Tag_{i}.Graph$
                  \EndIf
                \EndFor 
                \ForAll {$Tag_{j}\in Tag$} 
                  \If {$Tag_{j} is Feature$}      \quad 根据启发式规则或预定义规则库进行匹配
                     \State $Feature\;Feature_{j}=CreateFeature(Tag_{j})$  \quad 匹配特征并创建特征类
                     \State $Featurelist.pushback(Feature_{j})$    \quad 加入到特征链表     
                  \EndIf
                \EndFor  
                 \ForAll {$f_{i}\in S_{m}$}      \quad 寻找加工面图节点遍历
                  \If {$f_{i} \;compose\; MMCSG \in pGraph_{2}$}   \quad 是否在剩余子图中满足MMCSG
                     \State $recognizing\;Intersection\;feature$
                     \State $Featurelist.pushback(Feature_{i})$    \quad 识别相交特征并创建特征加入到特征链表
                  \EndIf
                \EndFor 
                 \ForAll {$f_{i}\in S$}                            
                  \If {$f_{i} \; Match \;Cylinder \;or \; Hole \;... \in pGraph_{1}$}    
                     \State $Featurelist.pushback(Feature_{i})$     \quad 寻找满足圆柱段、孔、倒角等非MMCSG特征并添加到链表;
                  \EndIf
                \EndFor  
            \EndFunction
        \end{algorithmic}
    \end{algorithm}
\end{CJK*}
\end{document}
相关标签: Windows文字处

上一篇:

下一篇: