php - Draw a line of fixed length from a fixed starting point towards ending point -


i stuck @ problem. trying solve 2 days. clueless. can simple clueless @ moment & appreciated.

i want make line a(x1, y1) b(x2, y2) of fixed length.

a.............b a....b........ a.............    b 

i have made mobile cricket scorer. in reports builds wagon wheel. used mobile human touch not accurate , people not touch boundary line (dark orange circle in image below).

but when generating report in php, must draw line fixed starting point boundary line in direction touched.

right wagon wheel looks this.

enter image description here

i have tried many ways accomplish failed. next idea draw line of fixed length fixed starting point (batting side) touch co-ordinates of fixed length line end @ boundary line no matter if users' touch not accurate.

i can calculate distance between starting point , touch point using in php

    $linelength = round( sqrt (pow(($wicketx-$x),2) + pow(($wickety-$y),2)), 2); 

but dont know how further adjust touch co-ordinates required length

please please please help.

p.s. question looked similar figure out. maths week calculate point along line a-b @ given distance a

i understand want find intersection of line through points , b circle. needn't center.

let center of circle have coordinates (xc, yc) , radius r.

any point along ab can written as

x = xa + t (xb - xa) = xc + (xa - xc) + t (xb - xa) = xc + xca + t xab y = ya + t (yb - ya) = yc + (ya - yc) + t (yb - ya) = yc + yca + t yab 

you plug in equation of circle

(x - xc)² + (y - yc)² - r² = (xca + t xab)² + (yca + t yab)² - r²                             = (xab² + yab²) t² + 2 (xca xab + yca yab) t + xca² + yca² - r²                            = 0 

this second degree equation need solve t. use solution positive t, on side of b. t, compute (x, y).


note if center, equation trivially reduces to

(xab² + yab²) t² = r² 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -