> For the complete documentation index, see [llms.txt](https://jona-projects.gitbook.io/kiwicalc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jona-projects.gitbook.io/kiwicalc/analytic-geometry/pointcollection.md).

# PointCollection

The `PointCollection` class represents a collection of points. Namely, a collection of `Point` objects.

#### Properties

* `points` - a list of points.

#### Create a new `PointCollection` object

The constructor accepts a collection of points. Each point can be represented via a `Point` object, or other collections such as `list`, `tuple` ,`set`, etc. For instance:

```python
my_points = PointCollection([Point((2, 6)), [2, 4], Point2D(9, 3)])
print(my_points)         
```

The points don't `have` to be in the same dimensions, but it makes much more sense that way. In addition, some features won't be available if the points have different dimensions. The `PointCollection` class has several subclasses: `Point1DCollection`, `Point2DCollection`, `Point3DCollection` and `Point4DCollection`. You should use them if you can, even if we're not using them in some examples for the sake of simplicity.

#### `add_point()`

You can add a new point to the collection via the `add_point()` method. For instance:

```python
my_points = PointCollection([Point((2, 6)), [2, 4], Point2D(9, 3)])
my_points.add_point(Point((5, 3)))
print(my_points)
                    
```

#### `remove_point()`

You can also remove points by their index. For example:

```python
my_points = PointCollection([Point((2, 6)), [2, 4], Point2D(9, 3)])
my_points.remove_point(0)  # remove the first point
print(my_points)
                    
```

#### Max and min distances

You can find the longest and shortest distances between any 2 points in the collection via the `longest_distance()` and `shortest_distance()`. In other words, this methods find the distance of the furthest and closest pair of points. However, this will only work if all of the points in the collection are in the same dimensions, namely, have the same number of coordinates. For instance:

```python
my_points = PointCollection([[1, -4, 5], [7, -5, -2], [5, 3, 9], [-2, 6, 4]])
print(my_points.longest_distance())
print(my_points.shortest_distance())
                    
```

You can also fetch the pairs of points:

```python
my_points = PointCollection([[1, -4, 5], [7, -5, -2], [5, 3, 9], [-2, 6, 4]])
longest_distance, longest_pair = my_points.longest_distance(get_points=True)
print(F"Longest Distance: {longest_distance}, Longest Pair: {longest_pair}")
shortest_distance, shortest_pair = my_points.shortest_distance(get_points=True)
print(F"Shortest Distance: {shortest_distance}, Shortest Pair: {shortest_pair}")
                    
```

#### Scatter points

You can scatter the points in 1D, 2D, 3D, and 4D. For example:

```python
# scatter in 1D
points = PointCollection([[1], [3], [5], [6]])
points.scatter()
                    
```

Output:

<figure><img src="/files/0L2jrhq48Qqt891QtZ3F" alt=""><figcaption></figcaption></figure>

```python
# scatter in 2D
points = Point2DCollection([[1, 2], [6, -4], [-3, 1], [4, 2], [7, -5], [4, -3], [-2, 1], [-3, 4], [5, 2], [1, -5]])
points.scatter()
                    
```

Output:

<figure><img src="/files/4Vp4ZvR8LRxo6DRFs019" alt=""><figcaption></figcaption></figure>

```python
# scatter in 3D
points = Point3DCollection([[random.randint(1, 100), random.randint(1, 100), random.randint(1, 100)] for _ in range(100)])
points.scatter()
                    
```

Output:

<figure><img src="/files/9Yc7Pfh9arAy9XbFmjnj" alt=""><figcaption></figcaption></figure>

```python
# Scatter in 4D
points = Point4DCollection(
    [[random.randint(1, 100), random.randint(1, 100), random.randint(1, 100), random.randint(1, 100)] for _ in
     range(100)])
    points.scatter()
                    
```

Output:

<figure><img src="/files/kvPLRjWZbK5gwH9E7hIZ" alt=""><figcaption></figcaption></figure>
