<p>No, a point does not have a length. A point is only a location - it has no extent in any direction.</p>

<p>You are correct in guessing that the function <code>vSize()</code> returns the distance from the origin to the point. The other function, <code>vSize2()</code> returns the square of that distance. This is used in calculating the distance, and in some cases it may be useful to work directly with the square of the distance instead of the distance. This avoids calculating square roots, so can lead to improvements in speed and accuracy.</p>

<hr>

<p>Note that as Nero points out, the functions are using only <code>int</code>s (integer variables and return values). The distance between a point and the origin is not in general an integer value, even if the coordinates of the point are all integers. The distance squared returned by <code>vSize2()</code> will be accurate, but the distance itself returned by <code>vSize()</code> will be accurate only to the nearest integer.</p>

CC BY-SA 3.0
2016-05-20T15:36:14.207Z
Additionally, the code for `vSize()` does not return very precise results as the square root of an integer is not necessarily also an integer, but the method returns an `int`. Actually, in most cases the given method will return imprecise results.
Nero
CC BY-SA 3.0
2016-05-20T20:22:29.413Z
It might be used as a hash of some kind. Or maybe they are using a integer quantized field.
joojaa
CC BY-SA 3.0
2016-05-21T09:56:39.100Z
Basically the integer is 64-bit. Will it make any difference in that case ?
sajis997
CC BY-SA 3.0
2016-05-21T12:48:31.720Z
64 bit integers allow for a [larger maximum number](https://en.wikipedia.org/wiki/9223372036854775807) than 32 bit integers, but they can still only take whole number values. You could ask why integers are used as a separate question, but that would require access to more of the code and some context on what it is used for. Without that context it is difficult to judge whether this would be on topic for Computer Graphics.
trichoplax is on Codidact now
CC BY-SA 3.0
2016-05-20T14:55:55.117Z
2016-05-20T15:52:07.877Z
2016-05-20T15:52:07.877Z
trichoplax is on Codidact now
<p>I am going though a functional source that has the following class:</p>

<pre class="lang-cpp prettyprint-override"><code> class Point3D
 {
       int x ,y,z;

       int vSize2() const
       {
           return x*x +
                  y*y +
                  z*z;
       }


       int vSize() const
       {
         return sqrt(vSize2());
       }           
 };
</code></pre>

<p>It is hard to understand the functionalities of the above two functions (<code>vSize2()</code> and <code>vSize()</code>). It seems to me that it is calculating the length between the point and the origin. </p>

<p>Any thoughts?</p>

<geometry>
Does a point have a length?
sajis997
# Does a point have a length?

(Asked by: username_0 on 2016-05-20)

I am going though a functional source that has the following class:

```cpp
 class Point3D
 {
       int x ,y,z;

       int vSize2() const
       {
           return x*x +
                  y*y +
                  z*z;
       }

       int vSize() const
       {
         return sqrt(vSize2());
       }           
 };

```

It is hard to understand the functionalities of the above two functions (`vSize2()` and `vSize()`). It seems to me that it is calculating the length between the point and the origin.

Any thoughts?

**Tags:** geometry


---

## 1 answers

### Answer by username_1 on 2016-05-20. Score: 5 | Accepted answer

No, a point does not have a length. A point is only a location - it has no extent in any direction.

You are correct in guessing that the function `vSize()` returns the distance from the origin to the point. The other function, `vSize2()` returns the square of that distance. This is used in calculating the distance, and in some cases it may be useful to work directly with the square of the distance instead of the distance. This avoids calculating square roots, so can lead to improvements in speed and accuracy.

---

Note that as username_2 points out, the functions are using only `int`s (integer variables and return values). The distance between a point and the origin is not in general an integer value, even if the coordinates of the point are all integers. The distance squared returned by `vSize2()` will be accurate, but the distance itself returned by `vSize()` will be accurate only to the nearest integer.

> **Comments:**
> **username_2**: Additionally, the code for `vSize()` does not return very precise results as the square root of an integer is not necessarily also an integer, but the method returns an `int`. Actually, in most cases the given method will return imprecise results.  
> **username_3**: It might be used as a hash of some kind. Or maybe they are using a integer quantized field.  
> **username_0**: Basically the integer is 64-bit. Will it make any difference in that case ?  
> **username_1**: 64 bit integers allow for a [larger maximum number](https://en.wikipedia.org/wiki/9223372036854775807) than 32 bit integers, but they can still only take whole number values. You could ask why integers are used as a separate question, but that would require access to more of the code and some context on what it is used for. Without that context it is difficult to judge whether this would be on topic for Computer Graphics.  

---

