0
我在3D空間中有一組邊界框(矩形)。計算每個框的邊界並將其存儲在名爲「RegionBounds」的字典中。此外,在名爲「PointsToCategorize」的列表中填充一組點,給定點(x,y,z)座標從填充的列表和要檢入的邊界框,我可以檢查點是否在框內或不。問題是,這是一個很大的數據集。要檢查的點數是1000,邊界框的數量是250-300。所以,如果我遍歷每個給定點的每個邊界框;總共耗時5-6分鐘。有沒有什麼有效的方法可以讓這個過程更快?如果可能的話,一個小代碼這樣做將是巨大的一組邊界框中的點分類
public struct iBounds {
public double x1, x2;
public double y1, y2;
public double z1, z2;
}
public struct iPoint {
public double x,y,z
}
Dictionary<String, iBounds> RegionBounds = new Dictionary<String, iBounds>();
List<iPoint> PointsToCategorize = new List<iPoint>();
int no_of_bounding_boxes = 300;
int no_of_points_to_categorize = 1000;
for (int i = 1; i <= no_of_bounding_boxes; i++)
{
String boundingBoxName = "bound_" + i;
iBounds boundingBox = new iBounds
{
x1 = Computed By Some Other method and Formulas,
x2 = Computed By Some Other method and Formulas,
y1 = Computed By Some Other method and Formulas,
y2 = Computed By Some Other method and Formulas,
z1 = Computed By Some Other method and Formulas,
z2 = Computed By Some Other method and Formulas
};
RegionBounds.Add(boundingBoxName, boundingBox);
}
////////////Start of Output section /////////////////////////
for(int i= 1; i < = PointsToCategorize.Count; i++){
foreach(var pair in RegionBounds)
{
String myboxNmame = pair.Key;
iBounds myboxBounds = pair.Value;
Console.WriteLine(PointInside(PointsToCategorize[i],myboxBounds).ToString());
}
}
////////////// End of Output section //////////////////
private bool PointInside(iPoint mypoint, iBounds boxToBeCheckedIn)
{
if (mypoint.x > boxToBeCheckedIn.x1) && (mypoint.x < boxToBeCheckedIn.x2){
if (mypoint.y > boxToBeCheckedIn.y1) && (mypoint.y < boxToBeCheckedIn.y2){
if (mypoint.z > boxToBeCheckedIn.z1) && (mypoint.z < boxToBeCheckedIn.z2){
return true;
}
}
}else{
return false;
}
}
歡迎所以有一個非常好的簡歷!由於您是新手,您可能需要查看此[鏈接](http://meta.stackexchange.com/a/5235/187716)。 – fferri