Skip to content

Instantly share code, notes, and snippets.

View sjhalayka's full-sized avatar

Shawn Halayka sjhalayka

View GitHub Profile
float min_3d_length = FLT_MAX;
float max_3d_length = FLT_MIN;
for (set<vertex_3>::const_iterator i = final_vertices.begin(); i != final_vertices.end(); i++)
{
if (i->length() > max_3d_length)
max_3d_length = i->length();
if (i->length() < min_3d_length)
min_3d_length = i->length();
"""Provides a function for performing 3D Dual Countouring"""
from common import adapt
from settings import ADAPTIVE, XMIN, XMAX, YMIN, YMAX, ZMIN, ZMAX
import numpy as np
import math
from utils_3d import V3, Quad, Mesh, make_obj
from qef import solve_qef_3d
#include <iostream>
using namespace std;
#include <opencv2/opencv.hpp>
using namespace cv;
#pragma comment(lib, "opencv_world340.lib")
int main(void)
{
Mat cat_img = imread("cat.png", CV_LOAD_IMAGE_GRAYSCALE);
def qmul(A_x, A_y, A_z, A_w, B_x, B_y, B_z, B_w):
C_x = A_x*B_x - A_y*B_y - A_z*B_z - A_w*B_w
C_y = A_x*B_y + A_y*B_x + A_z*B_w - A_w*B_z
C_z = A_x*B_z - A_y*B_w + A_z*B_x + A_w*B_y
C_w = A_x*B_w + A_y*B_z - A_z*B_y + A_w*B_x
return C_x, C_y, C_z, C_w
def qadd(A_x, A_y, A_z, A_w, B_x, B_y, B_z, B_w):
C_x = A_x + B_x
void idle_func(void)
{
custom_math::vector_3 grav_dir = sun_pos - mercury_pos;
float distance = grav_dir.length();
grav_dir.normalize();
custom_math::vector_3 accel = grav_dir*(G*sun_mass/pow(distance, 2.0));
float dt = 10000;
void multiply_4x4_matrices(float (&in_a)[16], float (&in_b)[16], float (&out)[16])
{
out[0] = in_a[0] * in_b[0] + in_a[4] * in_b[1] + in_a[8] * in_b[2] + in_a[12] * in_b[3];
out[1] = in_a[1] * in_b[0] + in_a[5] * in_b[1] + in_a[9] * in_b[2] + in_a[13] * in_b[3];
out[2] = in_a[2] * in_b[0] + in_a[6] * in_b[1] + in_a[10] * in_b[2] + in_a[14] * in_b[3];
out[3] = in_a[3] * in_b[0] + in_a[7] * in_b[1] + in_a[11] * in_b[2] + in_a[15] * in_b[3];
out[4] = in_a[0] * in_b[4] + in_a[4] * in_b[5] + in_a[8] * in_b[6] + in_a[12] * in_b[7];
out[5] = in_a[1] * in_b[4] + in_a[5] * in_b[5] + in_a[9] * in_b[6] + in_a[13] * in_b[7];
out[6] = in_a[2] * in_b[4] + in_a[6] * in_b[5] + in_a[10] * in_b[6] + in_a[14] * in_b[7];
out[7] = in_a[3] * in_b[4] + in_a[7] * in_b[5] + in_a[11] * in_b[6] + in_a[15] * in_b[7];
// https://stackoverflow.com/questions/785097/how-do-i-implement-a-bézier-curve-in-c
vector_3 getBezierPoint(vector<vector_3> points, float t )
{
int i = points.size() - 1;
while (i > 0)
{
for (int k = 0; k < i; k++)
{
points[k].x = points[k].x + t * ( points[k+1].x - points[k].x );
#include <cstdlib>
#include <ctime>
#include <GLUT/glut.h>
const int num_wide = 5;
const int num_tall = 4;
const int num_dims = 3; // xyz
GLfloat ctrlpoints[num_wide][num_tall][num_dims];
double mp_to_double(cpp_dec_float_100 &b)
{
ostringstream oss;
oss << b;
double ret;
istringstream iss(oss.str());
iss >> ret;
return ret;
// https://en.wikipedia.org/wiki/Simple_linear_regression
// https://en.wikipedia.org/wiki/Standard_deviation
float regression_line_slope(vector<float> &x, vector<float> &y)
{
if(x.size() != y.size())
return 0;
float x_mean = 0, y_mean = 0;