うしブログ

うしブログ

趣味で運営する、GeoGebraの専門ブログ。

(作業メモ)StartPoint要検証(2行の場合;テキスト変更時未定義問題)

(要修復)ToggleButton・RollPolygonWithoutSlipping・貯金時計・直感力トレーニング

GeoGebraで多角形の内部・辺上にある全ての格子点を返す方法

こんなことができます

下記のアプレットのように、多角形の内部・辺上にある格子点を表示させ、その数を計算できます。

下記のアプレットは、実際に頂点ABCをドラッグして、格子点の数がどう変化するかを確かめることができます。

 

準備

①任意の多角形を作成し、名前をusipolyとします。名前は、格子点を作成し終わるまでは変えないでください。

f:id:usiblog:20161113081321p:plain

 

多角形の内部および辺上にある全ての格子点を返す方法

入力バーに、以下のコマンドをコピペします。

RemoveUndefined[Sequence[If[IsInRegion[Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], n], usipoly] ≟ true, Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], n], false], n, 1, Length[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]]]]]

すると、格子点がリストとして作られます。

f:id:usiblog:20161113082010p:plain

格子点を作成した後であれば、多角形の名前(usipoly)は自由に変更しても大丈夫です。

 

内部および辺上の格子点の数を数値オブジェクトとして返すには、以下のコマンドを入力バーにコピペします。

Length[RemoveUndefined[Sequence[If[IsInRegion[Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], n], usipoly] ≟ true, Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], n], false], n, 1, Length[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]]]]]]

 

多角形の辺上にある全ての格子点を返す方法

入力バーに、以下のコマンドをコピペします。

RemoveUndefined[Sequence[If[Distance[Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], m], PolyLine[Join[{{Vertex[usipoly]}, First[{Vertex[usipoly]}]}]]] ≟ 0, Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], m], false], m, 1, Length[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]]]]]

すると、格子点がリストとして作られます。

f:id:usiblog:20161113082055p:plain

格子点を作成した後であれば、多角形の名前(usipoly)は自由に変更しても大丈夫です。

 

辺上の格子点の数を数値オブジェクトとして返すには、以下のコマンドを入力バーにコピペします。

Length[RemoveUndefined[Sequence[If[Distance[Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], m], PolyLine[Join[{{Vertex[usipoly]}, First[{Vertex[usipoly]}]}]]] ≟ 0, Element[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]], m], false], m, 1, Length[Flatten[Sequence[Sequence[(g, h), g, floor(Min[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[x(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1], h, floor(Min[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]), floor(Max[Sequence[y(Element[{Vertex[usipoly]}, i]), i, 1, Length[{Vertex[usipoly]}]]]) + 1]]]]]]