<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq" -->

---
title: Computing a Basis :: Box2D | daily.dev
description: A short technical note presents an efficient algorithm for computing an orthonormal basis (two additional orthogonal vectors) given a single normalized 3D...
canonical: https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Computing a Basis :: Box2D | daily.dev
og:description: A short technical note presents an efficient algorithm for computing an orthonormal basis (two additional orthogonal vectors) given a single normalized 3D...
og:url: https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq
og:image: https://api.daily.dev/og/posts/OGniVz5lQ.png
og:image:alt: Computing a Basis :: Box2D
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Computing a Basis :: Box2D

**[
        
            Box2D 
        
    ](https://daily.dev/sources/box2d)** · 1 min read · 0 upvotes · 0 comments

## Summary

A short technical note presents an efficient algorithm for computing an orthonormal basis (two additional orthogonal vectors) given a single normalized 3D vector, commonly needed in physics engines and graphics code. The trick relies on the fact that at least one component of a unit vector must be at least sqrt(1/3), which guards against numerical instability when picking a perpendicular vector. Code is given in C++, with a note that the branch can be replaced with a select operation for SIMD/SSE implementations.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://box2d.org/posts/2014/02/computing-a-basis>

## Questions this post answers

### How do I compute an orthonormal basis from a single normalized 3D vector efficiently?

Check whether the absolute value of the vector's x component is at least 0.57735 (sqrt(1/3)); if so, set b to (a.y, -a.x, 0), otherwise set b to (0, a.z, -a.y). Normalize b, then compute c as the cross product of a and b. This threshold guarantees a non-degenerate perpendicular vector since at least one component of any unit vector must be >= sqrt(1/3).

_Developers optimizing physics or graphics code can find more vector math patterns like this on daily.dev._

### Why is sqrt(1/3) used as a threshold when picking a perpendicular vector in 3D basis computation?

Sqrt(1/3), approximately 0.57735, is the value each component would have if a unit vector had all three components equal, since 3*s*s=1 gives s=sqrt(1/3). This means at least one component of any normalized vector must be greater than or equal to that value, so checking against it guarantees the chosen axis avoids degenerate near-zero cross products.

_For developers tuning numerical stability in physics engines, daily.dev surfaces similar algorithmic tricks._

## Similar posts on daily.dev

- [The Geometry Behind the Dot Product: Unit Vectors, Projections, and Intuition](https://daily.dev/posts/the-geometry-behind-the-dot-product-unit-vectors-projections-and-intuition-3humsmybb) · Towards Data Science · 0 upvotes · 0 comments
- [SIMD for Collision :: Box2D](https://daily.dev/posts/simd-for-collision-box2d-wsosdjqbv) · Lobsters · 0 upvotes · 0 comments
- [Dot product: Component vs. Geometric definition](https://daily.dev/posts/dot-product-component-vs-geometric-definition-5cseijaqp) · Eli Bendersky · 0 upvotes · 0 comments
- [Box3D Debuts As New Open-Source 3D Physics Engine](https://daily.dev/posts/box3d-debuts-as-new-open-source-3d-physics-engine-xsk1j9ymw) · Phoronix · 0 upvotes · 0 comments
- [Inscribed Spheres :: Box2D](https://daily.dev/posts/inscribed-spheres-box2d-dvq55o0po) · 
        
            Box2D 
        
     · 0 upvotes · 0 comments

---

Tags: [#math](https://daily.dev/tags/math), [#c++](https://daily.dev/tags/c++)

[View this post on daily.dev](https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Computing a Basis :: Box2D","url":"https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq"},"datePublished":"2026-08-23T12:16:49.035Z","dateModified":"2026-08-23T12:17:35.613Z","description":"A short technical note presents an efficient algorithm for computing an orthonormal basis (two additional orthogonal vectors) given a single normalized 3D...","image":"https://media.daily.dev/image/upload/s--VDukGCjf--/f_auto/v1722860399/public/Placeholder%2002","thumbnailUrl":"https://media.daily.dev/image/upload/s--VDukGCjf--/f_auto/v1722860399/public/Placeholder%2002","isAccessibleForFree":true,"articleSection":"\n        \n            Box2D \n        \n    ","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"\n        \n            Box2D \n        \n    ","logo":"https://media.daily.dev/image/upload/s--fmoS1AL5--/f_auto,q_auto/v1787487406/logos/box2d?_a=BAMAMicg0","url":"https://daily.dev/sources/box2d"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"math,c++","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"\n        \n            Box2D \n        \n    ","item":"https://daily.dev/sources/box2d"},{"@type":"ListItem","position":3,"name":"Computing a Basis :: Box2D"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/computing-a-basis-box2d-ognivz5lq#faq","mainEntity":[{"@type":"Question","name":"How do I compute an orthonormal basis from a single normalized 3D vector efficiently?","acceptedAnswer":{"@type":"Answer","text":"Check whether the absolute value of the vector's x component is at least 0.57735 (sqrt(1/3)); if so, set b to (a.y, -a.x, 0), otherwise set b to (0, a.z, -a.y). Normalize b, then compute c as the cross product of a and b. This threshold guarantees a non-degenerate perpendicular vector since at least one component of any unit vector must be >= sqrt(1/3). Developers optimizing physics or graphics code can find more vector math patterns like this on daily.dev."}},{"@type":"Question","name":"Why is sqrt(1/3) used as a threshold when picking a perpendicular vector in 3D basis computation?","acceptedAnswer":{"@type":"Answer","text":"Sqrt(1/3), approximately 0.57735, is the value each component would have if a unit vector had all three components equal, since 3*s*s=1 gives s=sqrt(1/3). This means at least one component of any normalized vector must be greater than or equal to that value, so checking against it guarantees the chosen axis avoids degenerate near-zero cross products. For developers tuning numerical stability in physics engines, daily.dev surfaces similar algorithmic tricks."}}]}
```

