Created
February 16, 2020 05:58
-
-
Save shibuiwilliam/a2f4b9b5bacd7891e9400d7bb304c9e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun initDistanceTable(){ | |
for (i in 0 until Constants.maxNumMultiplePoints+1){ | |
val tableRow = TableRow(this) | |
multipleDistanceTableLayout.addView(tableRow, | |
multipleDistanceTableLayout.width, | |
Constants.multipleDistanceTableHeight / (Constants.maxNumMultiplePoints + 1)) | |
for (j in 0 until Constants.maxNumMultiplePoints+1){ | |
val textView = TextView(this) | |
textView.setTextColor(Color.WHITE) | |
if (i==0){ | |
if (j==0){ | |
textView.setText("cm") | |
} | |
else{ | |
textView.setText((j-1).toString()) | |
} | |
} | |
else{ | |
if (j==0){ | |
textView.setText((i-1).toString()) | |
} | |
else if(i==j){ | |
textView.setText("-") | |
multipleDistances[i-1][j-1] = textView | |
} | |
else{ | |
textView.setText(initCM) | |
multipleDistances[i-1][j-1] = textView | |
} | |
} | |
tableRow.addView(textView, | |
tableRow.layoutParams.width / (Constants.maxNumMultiplePoints + 1), | |
tableRow.layoutParams.height) | |
} | |
} | |
} | |
private fun measureMultipleDistances(){ | |
if (placedAnchorNodes.size > 1){ | |
for (i in 0 until placedAnchorNodes.size){ | |
for (j in i+1 until placedAnchorNodes.size){ | |
val distanceMeter = calculateDistance( | |
placedAnchorNodes[i].worldPosition, | |
placedAnchorNodes[j].worldPosition) | |
val distanceCM = changeUnit(distanceMeter, "cm") | |
val distanceCMFloor = "%.2f".format(distanceCM) | |
multipleDistances[i][j]!!.setText(distanceCMFloor) | |
multipleDistances[j][i]!!.setText(distanceCMFloor) | |
} | |
} | |
} | |
} | |
private fun calculateDistance(objectPose0: Vector3, objectPose1: Vector3): Float{ | |
return calculateDistance( | |
objectPose0.x - objectPose1.x, | |
objectPose0.y - objectPose1.y, | |
objectPose0.z - objectPose1.z | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment