I'm trying to create a circle in 3D based off of 4 inputs.(adsbygoogle = window.adsbygoogle || []).push({});

Position1

Position2

LineLength1

LineLength2

The lines start at the positions, and they meet at their very ends.

To do this I've gotten the distance between the points, found the radius of the circle, the position of the center of the circle, and I then create a Null Space matrix from the vector pointing from Position1 to Position2.

This is the code I've written to create the basis

This works perfectly for when the positions share any single axis e.g. x = x, y=y or z=z. But when ever they don't share any axis, something goes haywire when it get's close to sharing the x axis. The closer you get to sharing the x axis, the top of the circle starts to flip sides with the bottom.Code (Text):

public List<Vector3> createBasis (Vector3 vec)

{

//Calculate orthogonal basis

int pivot = -1;

int free1 = -1;

int free2 = -1;

bool taken = false;

//Find Pivot and free variables

for (int i = 0; i <= 2; i++) {

taken = false;

if (pivot == -1 && vec[i] != 0) {

pivot = i;

taken = true;

}

if (free1 == -1 && !taken) {

free1 = i;

taken = true;

}

if (free2 == -1 && !taken) {

free2 = i;

taken = true;

}

}

if (pivot == -1)

pivot = 2;

Vector3 basis1 = new Vector3();

Vector3 basis2 = new Vector3();

//Setup basis vector 1

basis1[free1] = 1;

basis1[free2] = 0;

basis1[pivot] = vec[free1] / -vec[pivot];

//Setup basis vector 2

basis2[free2] = 1;

basis2[free1] = 0;

basis2[pivot] = vec[free2] / -vec[pivot];

//Calculate unit vector basis

basis1.Normalize();

basis2.Normalize();

List<Vector3> basis = new List<Vector3> ();

basis.Add (basis1);

basis.Add (basis2);

return basis;

}

video may help.

https://www.youtube.com/watch?v=yoDyyZUys8Y

You see how the circle is being messed up when ever it approaches the x axis? But when it's on the x or z axis, it's perfect.

What's wrong with my basis?

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Orthogonal Basis in 3d is flipping.

Loading...

Similar Threads for Orthogonal Basis flipping |
---|

I Orthogonal matrix construction |

I Is there a geometric interpretation of orthogonal functions? |

I Diagonalization and change of basis |

I Measures of Linear Independence? |

**Physics Forums | Science Articles, Homework Help, Discussion**