Menu

Converting Floats to IntPoints and back

artpen
2022-03-25
2022-03-26
  • artpen

    artpen - 2022-03-25

    Hi guys,

    I went all over the documenation and lots of examples. I am basicaly trying to convert each coordinate from float to Clipper Long and after Execute I need to conver all back to floats.
    So what I found is when I convert back it does not give me very acurate numbers. I need to go up to 1000 with my scale

    Here is how I do it, is it wrong?

    // Convert input Vecto3 List to intPoints. Including float precision
        // http://www.angusj.com/delphi/clipper/documentation/Docs/Overview/FAQ.htm
        private void ConvertToIntPoints()
        {
            foreach (var point in PathPoints)
            {
                float scaledX = point.x * scale; 
                float scaledY = point.z * scale;
                IntPoints.Add(new IntPoint(scaledX, scaledY));
            }
        }
    
        // Convert paths intPoints back to Vecto3s. Including float precision
        private void ConvertToFloat()
        {
            foreach (var path in offsetPaths)
            {
                for (int i = 0; i < path.Count; i++)
                {
                    float scaledX = path[i].X / scale;
                    float scaledZ = path[i].Y / scale;
                    OffsetPoints.Add(new Vector3(scaledX, 0.0f, scaledZ));
                }    
            }
        }
    
     
  • artpen

    artpen - 2022-03-25

    scale declared as float

     
  • Phil Stopford

    Phil Stopford - 2022-03-25

    The scale is essentially what controls the error that you see. The larger the scale you use, the less error should be observed. I tend to scale by 1E4 or more, and because I wanted accuracy more than anything else, I tend to use doubles rather than floats. You will see the range of error if you review the returned values from Clipper; you're simply shifting the decimal point when scaling down.

     
  • artpen

    artpen - 2022-03-26

    Thank you Phil. I just thought I am casting in a wrong way

     
MongoDB Logo MongoDB