math - Find point on a path in 3d space, given initial and final position and starting velocity vector -


let's have entity in 3d space , know position vector (x, y, z) , velocity vector (so orientation in space).

starting known point want reach known point b in 2 steps:

a) turn, following circular path known radius r, until point c

b) go straight point c final point b.

speed (scalar value) not important. velocity (vector) known, guess should define plane on circle resides, being tangent it, line between , b...

i want know how find coordinates (x, y, z) c , velocity vector of entity being there.

update: see working demo!

if understand correctly, situation (in plane containing a, b , v) shown in diagram below. points , b given, vector v , distance r. want find point c.

enter image description here

well, let vector w = (−v̂y, v̂x) unit vector perpendicular v. o = + r w.

now, |c − o| = r , (c − b)·(c − o) = 0 (where · dot product). combine these quadratic equation, can solve find 2 possible positions c. pick 1 right sign (c − b)×(c − o).

(there's second choice centre of circle, o = − r w, representing turning clockwise instead of anticlockwise. gives possibility c. guess you'll have use heuristic decide 1 prefer: maybe 1 smallest ∠aoc.)


st0rm asks doing in 3d (see comments). that's easy! plane containing a, b, , v has normal vector n = (a − b) × v. let u = n × v vector perpendicular both n , v, , let w = û (the unit vector in direction of u).

you'll need take account constraint c lies in same plane a: c·n = a.n, , "the right sign (c − b)×(c − o)" becomes "the right sign (c − b)×(c − o)·n".


having trouble solving system of equations?

well, if (c − b)·(c − o) = 0, (c − o + o − b)·(c − o) = 0, therefore (c − o)·(c − o) + (o − b)·(c − o) = 0, therefore c·(o − b) = o·(o − b) − r2.

you'll note equation plane, , c·n = a.n. intersect these 2 planes (see wikipedia details — can use simpler solution since planes orthogonal , can made orthonormal) equation of line on c lies: c = h + λl, say, l = n×(b − o). use (c − o)·(c − o) = r2 turn quadratic equation in λ. you'll find quadratic equation simplifies quite bit if rewrite equation of line c = h + λl + o occurrences of "− o" disappear.

enter image description here

here's implementation in python using numpy vector algebra. i'm sure can figure out how convert language of choice.

import math numpy import cross, dot numpy.linalg import norm  def unit(v):     """return unit vector in same direction v."""     return v / norm(v)  def turnpoints(a, b, v, r):     """generate possible turning instructions path b starts out in direction v, turns through part of circle of radius r until reaches point c (to determined), heads straight b. return each instruction in form (sense, c) sense -1 clockwise , +1 anticlockwise."""     n = unit(cross(a - b, v))   # unit normal plane containing a, b, v.     w = unit(cross(n, v))       # unit normal v lying in plane.     sense in (-1, +1):      # turn clockwise or anticlockwise?         o = + sense * r * w   # centre of turning circle.         bb = b - o         m = unit(bb)         # c lies on line h + l*l + o         h = dot(a, n) * n + (r**2 / norm(bb)) * m         l = cross(n, m)         # |c - o| = r**2 gives quadratic eqn in l coefficients a=1, b=0, c.         c = dot(h, h) - r**2         disc = - 4 * c          # discriminant of quadratic eqn.         if disc < 0:             continue            # no tangents (b inside circle).         elif disc == 0:         # 1 tangent (b on circle).             c = h + o             yield (sense, c)         else:                   # 2 tangents (b outside circle)             sign in (-1, +1):                 l = sign * math.sqrt(disc) / 2                 c = h + l * l + o                 # 1 choice c correct (the other involves                 # reversing direction).                 if dot(cross(c - b, c - o), n) * sense > 0:                     yield (sense, c) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -