Question – HELP DISPLAYING SONAR DATA ONTO A 2D MESH

  •  Void UpdateSonarDisplay()

  •     {

  •         //180 Scan

  •         //Arc: 3.14159265358979

  •         //range: 0.374736

  •         //m_RangeCells: 633 //amount qauds to draw based on the samples

  •         //Centrle Angle centre180Degree

  •         //Sectors: 200

  •         //Arc Radians: 3.14159265358979

  •         //Centre Angle Radians: 3.14159265358979 //centre at 180

  •         //Start Angle: 1.5707963267949

  •      

  •         //360 Scan

  •         //Arc: 6.28318530717959

  •         //range: 0.3744

  •         //m_RangeCells: 624 //amount qauds to draw based on the samples

  •         //Centrle Angle centre180Degree

  •         //Sectors: 400// spokes in a wheel

  •         //Arc Radians: 6.28318530717959

  •         //Centre Angle Radians: 3.14159265358979// centre at 180

  •         //Start Angle: 0

  •      

  •         //This is based on the 180

  •         double m_StartRange = 0.00;

  •         m_Arc = 3.14159265358979

  •         m_Range = 0.374736

  •         //m_Sectors = datafile.Swath.Sectors;

  •         m_RangeCells = 633

  •         m_CenterAngle = centre180Degree//enum

  •         m_Sectors = 200

  •              

  •         double arcRadians = 3.14159265358979

  •         double centreAngleRadians = 3.14159265358979

  •         double m_StartAngle = 1.5707963267949

  •         double anglePerSector = m_Arc / m_Sectors;

  •         double rangePerCell = (m_Range m_StartRange) / (double)m_RangeCells;

  •         vertices = new Vector3[m_Sectors * m_RangeCells * 4];
  •         colors = new Color[m_Sectors * m_RangeCells * 4];
  •         indices1 = new int[m_Sectors * m_RangeCells * 6];
  •         int vertexIndex = 0;

  •         int colorIndex = 0;

  •         int indexIndex = 0;

  •  

  • //This genrates all the positions needed and seems accurate

  •         for (int sector = 0; sector < m_Sectors; sector++)

  •         {

  •             int rangeCell = 0;

  •             float sectorStartAngle = (float)m_StartAngle + (float)anglePerSector * (float)sector;

  •             float sectorEndAngle = (float)sectorStartAngle + (float)anglePerSector;

  •             float sinStartAngle = Mathf.Sin(sectorStartAngle);

  •             float cosStartAngle = Mathf.Cos(sectorStartAngle);

  •             float sinEndAngle = Mathf.Sin(sectorEndAngle);

  •             float cosEndAngle = Mathf.Cos(sectorEndAngle);

  •             if (m_StartRange == 0.0f)

  •             {

  •                 vertices[vertexIndex++] = new Vector3(0, 0, 0);
  •                 vertices[vertexIndex++] = new Vector3((float)rangePerCell * sinStartAngle, (float)rangePerCell * cosStartAngle, 0.0f);
  •                 vertices[vertexIndex++] = new Vector3((float)rangePerCell * sinEndAngle, (float)rangePerCell * cosEndAngle, 0.0f);
  •  

  •                //This supposedly outlines the visual data based on the start range

  •                 colors[colorIndex++] = Color.blue;

  •                 colors[colorIndex++] = Color.red;

  •                 colors[colorIndex++] = Color.yellow;

  •                 rangeCell++;

  •             }

  •             for (; rangeCell < m_RangeCells; rangeCell++)

  •             {

  •                 float cellStartRange = (float)m_StartRange + (float)rangeCell * (float)rangePerCell;

  •                 float cellEndRange = (float)cellStartRange + (float)rangePerCell;

  •                 vertices[vertexIndex++] = new Vector3(cellStartRange * sinStartAngle, cellStartRange * cosStartAngle, 0.0f);
  •                 vertices[vertexIndex++] = new Vector3(cellEndRange * sinStartAngle, cellEndRange * cosStartAngle, 0.0f);
  •                 vertices[vertexIndex++] = new Vector3(cellEndRange * sinEndAngle, cellEndRange * cosEndAngle, 0.0f);
  •                 vertices[vertexIndex++] = new Vector3(cellStartRange * sinEndAngle, cellStartRange * cosEndAngle, 0.0f);
  •  

  •                  //This just covers the rest in black

  •                 colors[colorIndex++] = Color.black;

  •                 colors[colorIndex++] = Color.black;

  •                 colors[colorIndex++] = Color.black;

  •                 colors[colorIndex++] = Color.black;

  •             }

  •         }

  •  

  • //This is where the problem occurs. The mesh does not complete the full 180 or 360 depending on the //settings arc. it’s stops at 15 Degrees and draws over and over

  •         // Generate triangles

  •         for (int sector = 0; sector < m_Sectors; sector++)

  •         {

  •             int rangeCell = 0;

  •             int offset = (m_RangeCells * 4 1) * sector;

  •             if (m_StartRange > 0.0f)

  •                 offset = (m_RangeCells * 4) * sector;

  •             if (m_StartRange == 0.0f)

  •             {

  •                 indices1[indexIndex++] = offset++;

  •                 indices1[indexIndex++] = offset++;

  •                 indices1[indexIndex++] = offset++;

  •                 rangeCell++;

  •             }

  •             for (; rangeCell < m_RangeCells; rangeCell++)

  •             {

  •                 indices1[indexIndex++] = offset;

  •                 indices1[indexIndex++] = offset + 1;

  •                 indices1[indexIndex++] = offset + 2;

  •                 indices1[indexIndex++] = offset;

  •                 indices1[indexIndex++] = offset + 2;

  •                 indices1[indexIndex++] = offset + 3;

  •                 offset += 4;

  •             }

  •             yield return new WaitForSeconds(0.01f);
  •         }

  •     }

  • Read more here: Source link