vector - Calculate point on a circle in 3D space -


i scratching head time how this.

i have 2 defined vectors in 3d space. vector x @ (0,0,0) , vector y @ (3,3,3). random point on line between 2 vectors. , around point want form circle ( amount of points ) perpendicular line between x , y @ given radius.

hopefuly clear looking for. have looked through many similar questions, cant figure out based on those. help.

edit: (couldnt put comment adding here) @willywonka

hi, reply, had moderate success implementing solution, has trouble it. works of time, except specific scenarios when y point @ positions (20,20,20). if sits directly on axis fine.

but gets diagonal distance between perpendicular point , origin gets smaller reason , @ specific diagonal positions kinda flips perpendicular points.

image

here code at

    public vector3 x = new vector3(0,0,0);     public vector3 y = new vector3(0,0,20);      vector3 a;     vector3 b;      list<vector3> points = new list<vector3>();       void findperpendicular(vector3 x, vector3 y)     {          vector3 direction = (x-y);         vector3 normalized = (x-y).normalized;           float dotproduct1 = vector3.dot(normalized, vector3.left);         float dotproduct2 = vector3.dot(normalized, vector3.forward);         float dotproduct3 = vector3.dot(normalized, vector3.up);            vector3 dotvector = ((1.0f - mathf.abs(dotproduct1)) * vector3.right) +                             ((1.0f - mathf.abs(dotproduct2)) * vector3.forward) +                              ((1.0f - mathf.abs(dotproduct3)) * vector3.up);          = vector3.cross(normalized, dotvector.normalized);             b = vector3.cross(a, normalized);      } 

what want first find 2 orthogonal basis vectors of plane perpendicular line xy, passing through point choose.

you first need find vector perpendicular xy. this:

  • normalize vector xy first
  • dot xy x-axis
  • if small (for numerical stability let's < 0.1) must parallel/anti-parallel x-axis. choose y axis.
  • if not choose x-axis
  • for whichever chosen axis, cross xy 1 of basis vectors; cross this xy again second vector.
  • normalize them (not strictly necessary useful)

you have 2 basis vectors calculate circle coordinates, call them a , b. call point chose p.

then point on circle can parametrically calculated

q(r, t) = p + r * (a * cos(t) + b * sin(t))

where t angle (between 0 , 2π), , r circle's radius.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -