Created
April 6, 2012 22:11
-
-
Save roxlu/2323437 to your computer and use it in GitHub Desktop.
Parallel Transport Frames - from graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate spiral | |
int prev_vertex = gr.addVertex(Vec3(0,0,0)); | |
int prev_node = gr.addNode(new Node(prev_vertex)); | |
int num_edges = 30; | |
float angle = 0; | |
float radius = 2.0f; | |
float y = 0; | |
for(int i = 0; i < num_edges; ++i) { | |
angle += ((float)TWO_PI/(num_edges*0.25)); | |
float x = cos(angle) * radius; | |
float z = sin(angle) * radius; | |
int new_vertex = gr.addVertex(Vec3(x,y,z)); | |
int new_node = gr.addNode(new Node(new_vertex)); | |
gr.addEdge(new Edge(prev_node, new_node)); | |
prev_node = new_node; | |
prev_vertex = new_vertex; | |
y += 0.2; | |
} | |
// ------------------------------- | |
// Generate transporting frames | |
void Tubes::computeEdgeCoordinateSystems() { | |
vector<vector<Edge*> > paths; | |
if(!graph.findPaths(paths)) { | |
return; | |
} | |
vector<Edge*> edges; | |
for(int i = 0; i < paths.size(); ++i) { | |
edges = paths[i]; | |
if(edges.size() < 2) { | |
printf("path is too tiny..\n"); | |
continue; | |
} | |
Vec3 start = graph.getEdgeStartVertex(edges[0]); | |
Vec3 end = graph.getEdgeStartVertex(edges[1]); | |
Vec3 V = (end - start).normalize(); | |
Vec3 D(0,0,1); | |
Vec3 U(0,1,0); | |
Vec3 D_prev = D; | |
Vec3 U_prev = U; | |
Vec3 V_prev = V; | |
for(int j = 0; j < edges.size()-1; ++j) { | |
Edge* edge_a = edges[j]; | |
Edge* edge_b = edges[j+1]; | |
Vec3 va = graph.getEdgeStartVertex(edge_a); | |
Vec3 vb = graph.getEdgeEndVertex(edge_a); | |
Vec3 vc = graph.getEdgeEndVertex(edge_b); | |
Vec3 t0 = (vb - va).getNormalized(); | |
Vec3 t1 = (vc - vb).getNormalized(); | |
Vec3 B = cross(t0,t1); | |
// vectors are parallel, so just copy | |
if(B.length() <= 0.01) { | |
V = V_prev; | |
D = D_prev; | |
} | |
else { | |
B.normalize(); | |
float theta = acosf(dot(t0, t1)); | |
V.rotate(theta, B); | |
D.rotate(theta, B); | |
U.rotate(theta, B); | |
} | |
edge_a->setAxis(U, D, V); | |
V_prev = V.getNormalized(); | |
D_prev = D.getNormalized(); | |
U_prev = U.getNormalized(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small step size





big step size (fails?)
