Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Inaccurate measurments by ruler / measurement app in unity ARKit

Discussion in 'AR' started by ThoHer, Jul 10, 2018.

  1. ThoHer

    ThoHer

    Joined:
    Feb 27, 2018
    Posts:
    13
    I'm working on an application for room measurement, a ruler of sorts, using the ARKit in Unity3D. For this I am using raycasts to place objects (spheres), against the wall, and calculate the distance between those objects by getting the position of recognized walls, which the ARKit generates.

    The problems I have:

    • My placed objects are mostly a bit to far away from those ARKit walls.
    • Those objects are floating away when I move. So the measurements are not that precise.
    • Extra question: I would like to create a Gaze Pointer, which sets its angle to the angle of the wall, iam pointing to. (currently the pointer isnt set straight to the detected walls or neither to their angles in relation to the position/angle of the user/his tablet)
    The code (snippet):

    Code (CSharp):
    1.  
    2. // generate first point
    3.     Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);;
    4.     RaycastHit hit;
    5.  
    6.     if (Physics.Raycast(ray, out hit))
    7.     {
    8.             if (!arModeWall)
    9.         {
    10.             if (!continueMeasure)
    11.             {
    12.                 if (!firstTouch)
    13.                 {
    14.                     //Debug.Log("FirstDot");
    15.                     firstTouch = true;
    16.                     doLine = true;
    17.  
    18.                     if (fromToCalculation != 1)
    19.                         fromToCalculation = 1;
    20.                     //continueMeasure = true;
    21.  
    22.                     Vector3 cameraPos = new Vector3(Camera.main.transform.position.x,                      Camera.main.transform.position.y, +10);
    23.  
    24.                     //Create first sphere (nessacary for position)
    25.                     GameObject newPoint = Instantiate(distanceMeasuringSphere, hit.point, Quaternion.identity);
    26.                     newPoint.transform.parent = distanceMeasuringSphereContainer.transform;
    27.                     distanceMeasuringSphereArray.Add(newPoint);
    28.  
    29.                     //Create first LineRenderer (nessacary for Visuals)
    30.                     GameObject newLR = Instantiate(distanceMeasuringLr,      distanceMeasuringSphereArray[distanceMeasuringSphereArray.Count - 1].gameObject.transform.position, Quaternion.identity);
    31.                     newLR.transform.parent = distanceMeasuringLrContainer.transform;
    32.                     newLR.GetComponent<LineRenderer>().SetPosition(0, distanceMeasuringSphereArray[distanceMeasuringSphereArray.Count - 1].gameObject.transform.position);
    33.                     distanceMeasuringLineRendererArray.Add(newLR);
    34.  
    35.                     //Create first Text (nessacary for Distance)
    36.                     GameObject newDistanceText = Instantiate(distanceMeasuringText, hit.point, Quaternion.identity);
    37.                     newDistanceText.transform.parent = distanceMeasuringTextContainer.transform;
    38.                     distanceMeasuringTextArray.Add(newDistanceText);
    39.  
    40.                 }
    41.  
    It's the best solution I could think of to create a ruler.
    But I am open for improvement, Suggestions as well.

    Thank you very much for your help.


    Best,

    Thomas