Skip to content

Instantly share code, notes, and snippets.

View jcayzac's full-sized avatar

Julien Cayzac jcayzac

View GitHub Profile
@jcayzac
jcayzac / gist:1241840
Created September 26, 2011 08:20
Charles Bloom algorithm for sphere-cone intersection
V = sphere.center - cone.apex_location
a = V * cone.direction_normal
b = a * cone.tan
c = sqrt( V*V - a*a )
d = c - b
e = d * cone.cos
now if ( e >= sphere.radius ) , cull the sphere
else if ( e <=-sphere.radius ) , totally include the sphere
else the sphere is partially included.
@jcayzac
jcayzac / gist:1241858
Created September 26, 2011 08:31
My algorithm for sphere-cone intersection
V = sphere.center - cone.apex_location
a = dotProduct(V, cone.direction_normal)
p = a * cone_sin
q = cone_cos * cone_cos * dotProduct(V, V) - a*a
r = q - sphere_radius * sphere_radius
if ((p < sphere_radius) || (q > 0)) {
if (r < 2 * sphere_radius * p)
return -1; // Sphere and cone enveloppes intersect
else if (q < 0)
@jcayzac
jcayzac / gist:1241863
Created September 26, 2011 08:34
Charles Bloom algorithm for sphere-cone intersection (simplified)
V = sphere.center - cone.apex_location
a = dotProduct(V, cone.direction_normal)
x = cone.cos * sqrt(dotProduct(V,V) - a*a) - a*cone.sin
if (abs(x) > sphere.radius) {
if (x < 0)
return 1; // Sphere is totally included in cone
else
return 0; // Sphere and cone don't intersect at all
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcayzac
jcayzac / armv7-sincos.cpp
Created October 3, 2011 03:40
Fast sine/cosine for ARMv7+NEON
#include <math.h>
/// Computes the sine and cosine of two angles
/// in: angles = Two angles, expressed in radians, in the [-PI,PI] range.
/// out: results = vector containing [sin(angles[0]),cos(angles[0]),sin(angles[1]),cos(angles[1])]
static inline void vsincos(const float angles[2], float results[4]) {
static const float constants[] = {
/* q1 */ 0, M_PI_2, 0, M_PI_2,
/* q2 */ M_PI, M_PI, M_PI, M_PI,
/* q3 */ 4.f/M_PI, 4.f/M_PI, 4.f/M_PI, 4.f/M_PI,
@jcayzac
jcayzac / widen_ascii.py
Created December 16, 2011 07:48
Python: Convert all ASCII characters to their full-width counterpart
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
WIDE_MAP = dict((i, i + 0xFEE0) for i in xrange(0x21, 0x7F))
WIDE_MAP[0x20] = 0x3000
def widen(s):
"""
Convert all ASCII characters to the full-width counterpart.
#include <cstdio>
#include <unistd.h>
#include <cstdlib>
#include <X11/Xlib.h>
#include <X11/extensions/xf86vmode.h>
#include <iostream>
using ::std::cerr;
using ::std::endl;
int main(void) {
@jcayzac
jcayzac / Aurora (bug).png
Created January 21, 2012 06:11
Aurora bug
Aurora (bug).png
@jcayzac
jcayzac / test.md
Created February 2, 2012 09:15
Delete me

Title

This is a test of an extended markdown syntax for use in my blog. @more This is a video.

@tags Code, Algorithms, Blog, CSS Tutorials @date 2012-02-02T18:20:00 GMT+9 @from 139.5, 9.88 "Yokohama, Japan"

@jcayzac
jcayzac / rAF.js
Created February 7, 2012 02:50 — forked from paulirish/rAF.js
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel and Julien Cayzac
(function() {
var lastTime = 0,
vendors = ['ms', 'moz', 'webkit', 'o'],
x,