簡體   English   中英

n維空間中坐標的表示和命名

[英]Representation and naming of coordinates in n-dimensional space

目前,我正在制作一款Breakout游戲,並考慮了坐標的表示形式以及它們的命名約定。 在此特定示例中,您在二維空間中只有兩個坐標x和y。

在此處輸入圖片說明

是(甚至二維的)坐標系:數組的最佳表示形式嗎? 為什么在這種情況下使用int仍然有用呢? 什么時候切換到數組有意義? 似乎不明智的做法是,當您使用變量來描述變量出現的順序時,就像在坐標系中使用x和y一樣。

哪個會更有效? 使用二維數組比使用兩個基本整數快嗎? 將值更新為整數或數組會更快嗎? 我認為使用更大維度的數組要容易得多。

int[] coordinates = {1,2}; //initializing, which way is faster? 
int xPosition = 1;
int yPosition = 2;

xPosition = 2; //updating the coordinates, which way is faster?
yPosition = 3;
coordinates = {2, 3};

結束這種瘋狂:如果選擇int ,最好的變量名是什么? 這些是我的掙扎:

int xPosition, yPosition //a bit long
int xPos, yPos //looks short and clear to me, but maybe there is an 
//'normal' way to do it?
int xpos, ypos //short and looks less clear but represents better imo
// that it's one entity
int positionX, positionY //auto-complete takes twice as long
int posY, posX //harder to see what's meant here for me

正暗淡。 作為低層結構的數組已經足夠好,並且是針對您的情況的最佳選擇:

  • 這些坐標的大小是靜態的。
  • 您可以通過元素的索引輕松訪問元素。
  • 迭代要快得多且易於閱讀。
  • 無需搜索或排序算法。

只要確保您最初定義了確切的尺寸即可避免鑄造。

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM