<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k" -->

---
title: Ray tracer for those who skipped the math class | daily.dev
description: A beginner-friendly tutorial builds a minimal ray tracer in roughly 100 lines of C++, avoiding heavy math notation while explaining vector operations...
canonical: https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Ray tracer for those who skipped the math class | daily.dev
og:description: A beginner-friendly tutorial builds a minimal ray tracer in roughly 100 lines of C++, avoiding heavy math notation while explaining vector operations...
og:url: https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k
og:image: https://api.daily.dev/og/posts/wNh7aUJ0k.png
og:image:alt: Ray tracer for those who skipped the math class
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.

# Ray tracer for those who skipped the math class

**[zserge's blog](https://daily.dev/sources/zserge)** · 14 min read · 0 upvotes · 0 comments

## Summary

A beginner-friendly tutorial builds a minimal ray tracer in roughly 100 lines of C++, avoiding heavy math notation while explaining vector operations (addition, subtraction, dot product, unit vectors), sphere-ray intersection using the quadratic formula, and scene composition with spheres and lights. It progresses from rendering plain ASCII silhouettes to shaded spheres with diffuse and specular lighting, and finishes with tips for exporting PGM images and ideas for extending the tracer with shadows, materials, and additional shapes. Full source code is linked on GitHub.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://zserge.com/posts/raytracer>

## Questions this post answers

### How do you calculate the intersection between a ray and a sphere in a ray tracer?

You substitute the ray equation O+tD into the sphere equation (S-C)·(S-C)=r² and solve the resulting quadratic equation for t, where a=D·D, b=2(P·D), c=P·P-r², and P=O-C. The discriminant b²-4ac being negative means no intersection; otherwise the two roots give the near and far intersection distances along the ray.

_daily.dev surfaces graphics programming deep dives for developers building their own renderers from scratch._

### How do you compute diffuse and specular lighting for a sphere without a full graphics engine?

Diffuse lighting uses the dot product between the light direction and the surface normal, clamped to zero and scaled, such as max(0, (l·n)*0.7). Specular highlights raise that same dot product to a high power, like pow(max(0,l·n),70)*0.4, then both terms are added to the base sphere color multiplied by the light color.

_Developers prototyping lighting models can find hands-on graphics tutorials curated on daily.dev._

## Similar posts on daily.dev

- [Software rendering in 500 lines of bare C\+\+](https://daily.dev/posts/software-rendering-in-500-lines-of-bare-c--8zxoc44yj) · Hacker News · 0 upvotes · 0 comments
- [3D Gaussian Splatting in a Weekend](https://daily.dev/posts/3d-gaussian-splatting-in-a-weekend-lexrkdrgi) · Hacker News · 1 upvotes · 0 comments

---

Tags: [#game-development](https://daily.dev/tags/game-development), [#algorithms](https://daily.dev/tags/algorithms), [#c++](https://daily.dev/tags/c++), [#graphics-programming](https://daily.dev/tags/graphics-programming)

[View this post on daily.dev](https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k)

```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":"Ray tracer for those who skipped the math class","url":"https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k"},"datePublished":"2026-08-23T10:20:24.800Z","dateModified":"2026-08-23T10:21:25.128Z","description":"A beginner-friendly tutorial builds a minimal ray tracer in roughly 100 lines of C++, avoiding heavy math notation while explaining vector operations...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/60c8d9845141edd23a9a63bc30999346?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/60c8d9845141edd23a9a63bc30999346?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"zserge's blog","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":"zserge's blog","logo":"https://media.daily.dev/image/upload/s--KQnFBOIT--/f_auto,q_auto/v1787480407/logos/zserge","url":"https://daily.dev/sources/zserge"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"game-development,algorithms,c++,graphics-programming","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"zserge's blog","item":"https://daily.dev/sources/zserge"},{"@type":"ListItem","position":3,"name":"Ray tracer for those who skipped the math class"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/ray-tracer-for-those-who-skipped-the-math-class-wnh7auj0k#faq","mainEntity":[{"@type":"Question","name":"How do you calculate the intersection between a ray and a sphere in a ray tracer?","acceptedAnswer":{"@type":"Answer","text":"You substitute the ray equation O+tD into the sphere equation (S-C)·(S-C)=r² and solve the resulting quadratic equation for t, where a=D·D, b=2(P·D), c=P·P-r², and P=O-C. The discriminant b²-4ac being negative means no intersection; otherwise the two roots give the near and far intersection distances along the ray. daily.dev surfaces graphics programming deep dives for developers building their own renderers from scratch."}},{"@type":"Question","name":"How do you compute diffuse and specular lighting for a sphere without a full graphics engine?","acceptedAnswer":{"@type":"Answer","text":"Diffuse lighting uses the dot product between the light direction and the surface normal, clamped to zero and scaled, such as max(0, (l·n)*0.7). Specular highlights raise that same dot product to a high power, like pow(max(0,l·n),70)*0.4, then both terms are added to the base sphere color multiplied by the light color. Developers prototyping lighting models can find hands-on graphics tutorials curated on daily.dev."}}]}
```

