Giter Site home page Giter Site logo

bezier-curve-tangents's Introduction

About

This is a Bezier Curve tangent demonstration which may not look visually incredible, but is the baseline for something greater.

I recommend familiarizing yourself first with the concept of a Bezier curve if you are not already. Another good link is this page on the derivative of a n degree bezier curve.

Purpose

For effective raycasting on curved surfaces (see this project), I needed to find the tangents of Bezier curves which intersect some point.

My initial approach was to solve it mathematically. For degree 2 curves, the equation is a power 3 polynomial, which is reasonable. For degree n, it's a polynomial of power 2n-1; I am not writing a polynomial solver for this.

I implemented up to degree 3; The degree 3 curve uses a flattened approximation to figure out approximate tangents by brute force. This is not elegant, but it is fairly efficient, and should work well for higher degrees too.

Mathematical approach

We have the equation of a n-degree Bezier curve, Bx(t) and By(t). The derivatives are B'x(t) and B'y(t). And we have a point (x, y).

We want the [0, n] possible equations tangent to the curve that intersect (x, y).

These may be computed through the observation (By(t) - y)/(Bx(t) - x) -= B'y(t)/B'x(t) This results in a polynomial of degree 2n-1.

Usage

Compile src/Main.java and run it. It should create a window.

With the application running, left click to place points for the Bezier curve. Move the mouse around to view tangents to the curve. Right click or spacebar to clear the curve.

Examples

Sample image

Sample gif

bezier-curve-tangents's People

Contributors

andy98725 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.