# Computational Geometry Primitives in ShareOI: Convex Hull and Rotating Calipers Resources

> Explore computational geometry primitives like convex hull and rotating calipers in the hzwer/shareoi repository. Find lecture slides on theory but not direct code implementations.

- Repository: [hzwer/shareoi](https://github.com/hzwer/shareoi)
- Tags: tutorial
- Published: 2026-03-03

---

**The shareOI repository provides lecture slides covering convex hull and rotating calipers theory in its `计算几何` folder, containing files like `计算几何基础知识_陈胤伯.pdf` and `叉积的应用_卓亮.pdf`, though source code implementations are not currently included in the repository.**

The **shareOI** repository by hzwer is a curated archive of competitive programming teaching materials designed for Olympiad in Informatics (OI) contestants. While the repository extensively covers **computational geometry primitives like convex hull and rotating calipers** through PDF presentations and slide decks, it currently focuses on theoretical explanations rather than executable source code. This article examines the geometric algorithm resources available in the repository and provides reference implementations that complement the existing lecture materials.

## Computational Geometry Resources in ShareOI

### Repository Structure and File Organization

The shareOI repository organizes content into topic-based directories under the root, following the naming convention `<topic>_<author>.<extension>`. The **`计算几何`** (Computational Geometry) folder specifically houses materials explaining geometric algorithms and their mathematical foundations.

### Key Slide Decks for Geometric Algorithms

Within the `计算几何` directory, two critical files cover the primitives mentioned in your query:

- **`计算几何基础知识_陈胤伯.pdf`**: Found at `计算几何/计算几何基础知识_陈胤伯.pdf`, this slide deck introduces fundamental convex hull concepts and geometric proofs essential for OI problem solving.
- **`叉积的应用_卓亮.pdf`**: Located at `计算几何/叉积的应用_卓亮.pdf`, this presentation details cross-product applications that underpin both convex hull construction and rotating calipers optimization.

## Convex Hull Implementation: Monotone Chain Algorithm

While the repository contains theoretical explanations in `计算几何基础知识_陈胤伯.pdf`, the following C++ implementation demonstrates **Andrew's monotone chain algorithm** for convex hull construction in O(n log n) time complexity.

```cpp
#include <bits/stdc++.h>
using namespace std;

struct Point {
    long long x, y;
    bool operator<(Point const& other) const {
        return x < other.x || (x == other.x && y < other.y);
    }
    bool operator==(Point const& other) const {
        return x == other.x && y == other.y;
    }
};

// cross product (b - a) × (c - a)
long long cross(Point a, Point b, Point c) {
    return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}

// returns vertices of the convex hull in counter‑clockwise order
vector<Point> convexHull(vector<Point> pts) {
    sort(pts.begin(), pts.end());
    pts.erase(unique(pts.begin(), pts.end()), pts.end());
    if (pts.size() <= 1) return pts;

    vector<Point> lower, upper;
    for (auto& p : pts) {
        while (lower.size() >= 2 && cross(lower[lower.size()-2], lower.back(), p) <= 0)
            lower.pop_back();
        lower.push_back(p);
    }
    for (int i = (int)pts.size() - 1; i >= 0; --i) {
        Point p = pts[i];
        while (upper.size() >= 2 && cross(upper[upper.size()-2], upper.back(), p) <= 0)
            upper.pop_back();
        upper.push_back(p);
    }
    lower.pop_back();
    upper.pop_back();
    lower.insert(lower.end(), upper.begin(), upper.end());
    return lower;
}

```

This implementation utilizes the cross product logic detailed in `计算几何/叉积的应用_卓亮.pdf` to determine point orientation during hull construction. The `convexHull` function first sorts points lexicographically, then builds lower and upper hulls using the `cross` product to maintain convexity.

## Rotating Calipers for Convex Polygon Diameter

The rotating calipers technique, often covered in advanced computational geometry slides, solves the **convex polygon diameter problem** in linear O(n) time after hull computation.

```cpp
long long dist2(Point a, Point b) {
    long long dx = a.x - b.x, dy = a.y - b.y;
    return dx*dx + dy*dy;
}

// assumes 'hull' is a convex polygon in CCW order
long long rotatingCalipersDiameter(const vector<Point>& hull) {
    int n = hull.size();
    if (n == 1) return 0;
    if (n == 2) return dist2(hull[0], hull[1]);

    long long best = 0;
    int j = 1;
    for (int i = 0; i < n; ++i) {
        // advance j while area increases
        while (cross(hull[i], hull[(i+1)%n], hull[(j+1)%n]) >
               cross(hull[i], hull[(i+1)%n], hull[j]))
            j = (j + 1) % n;
        best = max(best, dist2(hull[i], hull[j]));
        best = max(best, dist2(hull[(i+1)%n], hull[j]));
    }
    return best;
}

```

The `rotatingCalipersDiameter` function maintains antipodal point pairs using the `cross` product to detect maximum distance. This approach aligns with the mathematical foundations presented in `计算几何/叉积的应用_卓亮.pdf`, applying vector cross products to determine when to advance the rotating caliper arms.

## Extending ShareOI with Source Code

Currently, shareOI follows a slide-centric model without executable source files. To bridge the gap between theory and practice, contributors could add a `代码/` subdirectory within `计算几何/` containing the above `convexHull` and `rotatingCalipersDiameter` implementations. This would complement the theoretical content in `计算几何基础知识_陈胤伯.pdf` and support practical OI contest preparation.

## Summary

- The **shareOI** repository organizes computational geometry materials under the `计算几何` folder using Chinese-language PDF slides authored by competitive programming experts.
- **`计算几何基础知识_陈胤伯.pdf`** and **`叉积的应用_卓亮.pdf`** provide the theoretical foundation for convex hull algorithms and rotating calipers techniques.
- **Andrew's monotone chain algorithm** achieves O(n log n) convex hull construction by leveraging cross-product orientation tests to build lower and upper hulls.
- **Rotating calipers** computes convex polygon diameter in O(n) linear time by maintaining antipodal point pairs and advancing them based on cross-product area comparisons.
- The repository currently lacks source code implementations but accepts contributions following the `<topic>_<author>.<extension>` naming convention.

## Frequently Asked Questions

### Does shareOI contain source code implementations for convex hull algorithms?

No, the repository currently contains only lecture slides and PDF presentations such as `计算几何基础知识_陈胤伯.pdf`. The `计算几何` folder provides theoretical explanations suitable for implementing convex hull algorithms yourself, but you will not find `.cpp` or `.py` source files in the current repository structure.

### What file formats are used in the computational geometry section?

The `计算几何` directory uses PDF and PPTX formats exclusively. Files follow the naming pattern `<topic>_<author>.<extension>`, such as `叉积的应用_卓亮.pdf`, ensuring immediate visibility of the content creator and subject matter.

### How is the repository organized for competitive programming topics?

ShareOI uses a topic-based hierarchy with top-level folders like `计算几何` (Computational Geometry), `图论` (Graph Theory), and `数学` (Mathematics). Each folder contains slide decks authored by competitive programming experts, with the README at the repository root providing a comprehensive index of all available materials.

### Can I use the rotating calipers technique for OI contests?

Yes, rotating calipers is a standard OI technique for solving problems involving convex polygon diameter, width, and minimum bounding rectangle. The algorithm runs in O(n) time after O(n log n) convex hull preprocessing, making it efficient for contest constraints. The mathematical principles are covered in the repository's cross-product application slides.