Skip to content

Instantly share code, notes, and snippets.

View jcchurch's full-sized avatar

James Church jcchurch

View GitHub Profile
@jcchurch
jcchurch / quickPlot.m
Last active October 12, 2015 21:18
Quickly plot matlab data.
function quickPlot(varargin)
% Quickly plot point clouds of data.
% This works for up to 5 datasets of
% 1D or 2D or 3D data, regardless of the
% row-order or column-order format.
%
% Also works with 2D or 3D matrices.
%
% How to use this function:
% --> Give it data. That's pretty much it.
@jcchurch
jcchurch / findRotationMatrix.m
Created September 25, 2012 15:38
Given vectors 'u' and 'v', this function finds a rotation matrix 'R' to satisfy the property R*u=v.
function R = findRotationMatrix(u, v)
% Given vectors 'u' and 'v', this function finds a
% rotation matrix 'R' to satisfy the property R*u=v.
%
% Input: 'u' and 'v' must be a 3 by n set of vectors.
% Output: 'R' is a 3 by 3 by n matrix of rotation matrices
%
% This satisfies the requirement of R(:,:,i) * u(:, i) = v(:, i),
% where i is one column within matrices u and v.
@jcchurch
jcchurch / eig3.m
Created August 21, 2012 21:49
Solving Many, Many 3 by 3 Eigenvalue Problems in Matlab
function [pp qq rr] = eig3(a, b, c, d, e, f, g, h, i)
% This is my 3 by 3 eigenvalue solver.
% It takes 9 variables: the 9 elements of a 3 by 3 array,
% arranged in this order:
%
% [ [ a b c ]
% [ d e f ]
% [ g h i ] ]
%
% This will actually solve many 3 by 3 eigenvalue problems
@jcchurch
jcchurch / gist:3025492
Created June 30, 2012 20:58
Demonstration of Triangle Circumcircle creation
>> TRI
TRI =
9 13 16
6 4 7
15 14 17
10 11 13
17 14 16
9 7 10
@jcchurch
jcchurch / drawCircles.m
Created June 30, 2012 20:56
Drawing Circles in Matlab
function drawCircles(center,radius,NOP,style)
%------------------------------------------------------------------------------
% CIRCLE(CENTER,RADIUS,NOP,STYLE)
% This routine draws a circle with center defined as
% a vector CENTER, radius as a scaler RADIS. NOP is
% the number of points on the circle. As to STYLE,
% use it the same way as you use the rountine PLOT.
% Since the handle of the object is returned, you
% use routine SET to get the best result.
%
@jcchurch
jcchurch / tricenters.m
Created June 30, 2012 20:50
Finding the circumcircles of a list of triangles
function [CENTERS, RADII] = tricenters(TRI, X, Y)
% This function takes the same parameters as the function 'trimesh' does, since they require the same inputs.
% INPUTS:
% TRI: A set of triangle indices. (N-by-3, where N is the number of triangles.)
% X: The X coordinate of the triangle indices.
% Y: The Y coordinate of the triangle indices.
%
% OUTPUTS:
% CENTERS: A 2D matrix of N-by-2, where N is the number of triangles in TRI.
% Each entry is a X, Y coordinate of a circumcenter.
@jcchurch
jcchurch / thereIsACycle.m
Created March 7, 2012 16:42
Determine if a graph contains a cycle.
function yes = thereIsACycle(G)
% G is an n-by-n association matrix.
% An edge is defined by anything in that
% matrix that is not 0 and not positive infinity.
% Elements along the diagonal are ignored.
% Returns 1 if there is a cycle. 0 otherwise.
yes = 0;
n = size(G, 1);
seen = zeros(1, n);
@jcchurch
jcchurch / distancePointToLineSegment.m
Created March 2, 2012 22:42
Distance from point to the nearest point along a line segment.
function distance = distancePointToLineSegment(p, a, b)
% p is a point
% a is the start of a line segment
% b is the end of a line segment
pa_distance = sum((a-p).^2);
pb_distance = sum((b-p).^2);
unitab = (a-b) / norm(a-b);
@jcchurch
jcchurch / pig.py
Created November 5, 2011 18:04
Convert the binary in the Phreaknic program to ASCII
#!/usr/bin/env python
message = "010100000110100101100111001000000111100101101111011101010010011101110010011001010010000001100001001000000110010001101001011000110110101100101110"
bytes = []
i = 0
while i < len(message):
bytes.append( message[i:i+8] )
i += 8
@jcchurch
jcchurch / Honeycomb.java
Created October 18, 2011 16:15
Detection of Hexes in a Cartesian Plane
import java.util.Scanner;
// This is another problem submission from a programming practice.
// The problem description can be found here:
// http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=374&page=show_problem&problem=2697
// Solved this one in approximately 1 hour.
public class Honeycomb {
public static void main(String[] args) {