analytics

Monday, November 16, 2015

Knowing SSA of triangle find other 2 angles approximately without inverse trig functions

This is for when you know 2 sides and an angle of a triangle and you want to find the other 2 angles approximately without using inverse trig functions...
The formula is:
In addition it gets 45-45-90 and Equilateral triangles exactly right! The 180-C can of course be replaced with pi-C when working in radians... There might be a kind of 3 variable Cauchy series that this uses averages of the first two terms of, I'll have to look further...

Saturday, November 14, 2015

Simple point in polygon test

I've seen a few ways to test for whether a point is in a convex polygon or not that necessitated using inverse trig functions, but this one is all easily calculated the distance functions can be left without taking the square root and just comparing distance-squared instead...
R and L are exactly the points you get when you rotate he line AB 90 degrees around it's midpoint... I think the nice thing is how the reasoning might extend to 3d convex polytopes with L and R making a line orthogonal to each face...

Friday, November 13, 2015

A standard form for adjacency matrices to solve the graph isomorphism problem

Supposing you have some graph with no more than one edge between vertices:
Here A, B, and C are all connected to themselves but they don't have to be, the above graph has adjacency matrix:
Indicating with a 1 where a row, column pair of vertices are connected...

Now a problem is to find a standard form for this and all  adjacency matrices corresponding to isomorphic graphs, though maybe the vertices are labeled differently...

First define a row's C to be a binary number corresponding to the row with the most significant digit to the right.. for example the first row above reads as 1100 so that would be the binary number for decimal 3 or 2^0 + 2^1

The algorithm I'm proposing is to simultaneously swap two rows and corresponding columns producing a new matrix if it increases a row's C with importance towards the top row. For example, swap two columns and corresponding rows if it either increases the first row's C or if that's not possible,  the second rows C while also not making the first row's C less, or if that's not possible swap so the third row's C is increased while at the same time not making row 1's and row 2's C less, etc... Each iteration of the algorithm I call an "improvement" of the adjacency matrix, the algorithm is done when no more improvements are possible...



Above is 3 steps of the algorithm describing which rows and columns are to be swapped highlighted in red and which row is improved on the new matrix after the swapping... The final matrix on the right can not be improved by the above definition by swapping any pair of rows and  corresponding columns... I think the exact specifics of how to choose which rows and corresponding columns is not important to the final result which by definition can not be improved...

So the final matrix is I believe in a standard form for all adjacency matrices corresponding to isomorphic graphs. In other words all adjacency matrices corresponding to isomorphic graphs and only to isomorphic graphs will improve to a particular unique standard matrix at the end of the algorithm...


Wednesday, November 11, 2015

Easier Bezier by 2nd derivative smoothing

So supposing you have n points on the plane with n greater than or equal to 4 and you want to find a smooth curve through them, you could do a n-degree bezier curve through them but that takes exponential time with respect to n to calculate or you could use bezier splines of a lesser degree but if you use , say, quadratic bezier splines through the n points directly there is a smoothness problem... The approach I'll outline below is to generate with a formula the 2*n-1 "halfway" points between known points then use quadratic bezier curves to interpolate but the way the "halfway" points are calculated gives a smooth final result...

So first we take our n points and label them A(2*(j)-1) for j from 0 to n, and from here on call them A(i)... Then we use this formula:
 This formula is saying that the 2nd derivative by divided differences at a point should be the average of the 2nd derivative at the point before it and the point after it...

Now here is a python program to figure out what the i values should be in the formula above to get the right number of equations for the number of new "halfway" points :

n=7
d = 1.0*(2*n-6)/(n-2)
for i in range(0, n-1):
    print(round(3+i*d))

For n=4 we get:
3,4,5

For n = 5 an odd number of points, we need 4 equations for the 4 in between points so we make the i's using the program::
3,4,6,7

For n = 6 there are 5 in between points we need equations for so we make the i's:
 3,4,6,8,9

For n = 7:
3,5,6,8,9,11


For n = 6 we know the six points A1, A3, A5, A7, A9,A11 and we want to know A2, A4, A6, A8, A10 so we use the i values from the program {3,4,6,8,9} and get five equations to solve:




Then the third step is to use these newly generated points to compute the quadratic Bezier paths between odd labeled points (I used a graphics program to manually draw the Beziers so they don't go exactly through the center of each point but mathematically they would)...




Compare this to using quadratic Beziers directly...

And there are some issues using just Beziers with even number of points about how exactly to divide the curve into quadratics because you need groups of 3 points for quadratic Beziers...

Monday, November 9, 2015

4 point sigmoidal elliptical curve

H and J are used to smoothly blend from one elliptical parameterization to another to produce the curve... the final curve is parameterized over [-pi/2] to [pi]... It might be good for something like designing fonts because it can do circular arcs that are found in a lot of letters well that bezier splines don't manage very well...

Sunday, November 8, 2015

Elliptical Pizza Theorem


So to find the ellipse you find 2 additional points with the formulas above and then the well known method for drawing a conic through 5 points: conic through 5 points.. I think it does a nice job of describing how a pizza will look with perspective if lines perpendicular to the viewing plane are drawn to the right, top, and left of the pizza, calling those P1, P2, and P3 respectively...

**UPDATE**


Actually I was suggesting my above answer to the people at geogebra.org and they told me about this nice parametric equation that only needs the center point and any 2 points on the ellipse, where A is the center:

f(t)=A+(B-A)*sin(t)+(C-A)*cos(t), 

at 0 it equals C, at 1/2)*Pi it equals B, then at 2*pi back to C! 
This one just wows me after as hard as I worked to figure out the one above...
And from that I derived this one:

f(t) = (1/2)*D+(1/2)*B+((1/2)*B-(1/2)*D)*sin(t)+(C-(1/2)*D-(1/2)*B)*cos(t)


Which given 3 points on the ellipse parameterizes it so that between B and D is the shorter axis...

f(pi) gives the opposing point on the long axis that C is on...


Alternative Ellipse:


Friday, November 6, 2015

Experimental comparison of G-decomposition of waves vs. Fourier

Here F is the Fourier style decomposition, for 5 points , and G is the new decomposition I've been working with, written also for five points:




So I tried not to cherry pick these values, I've gotten similar results with every set of points I've tried so far, but let's let the points be [1,1],[3,2],[5,5],[7,3],[9,2] and solve for the coefficients:




I think the problem with the Fourier is that it maxes to 6 height when the largest point is only 5, the G decomposition seems more reasonable,



**Note**
I don't know if the exponents in G cause the coefficients to get too large with a large number of points that will require some more investigation...And of course using powers of trigonometric functions might make them too costly to computer, but there might be some use cases where that isn't as important as the best fit to the points... There might even be some variations between these two where you use some small powers of sines and cosines and some multiples of frequencies...