Re: [Flashcoders] Math question: find coordinates of a point
Couldn't i adapt the 'circle-method' to AS? No idea how i'd figure out the equation of these circles, but it should be possible, since i've got their centre and their radius. Say P1 = (x1, y1) is the position of the first point and P2 = (x2, y2) the position of the second. Say R1 is the distance from P1 and R2 the distance from P2. You want Q = (x,y) such that (x-x1)(x-x1)+(y-y1)(y-y1) = R1*R1 and (x-x2)(x-x2)+(y-y2)(y-y2) = R2*R2 This is basically a pair of simultaneous equations, but it's a bit tricky. One way to simplify it slightly is to consider the point R which lies between P1 and P2. Its position is R=P1+t*(P2-P1), where t=R1/(R1+R2) [or, to put it more neatly, R = (R2*P1 + R1*P2) / (R1 + R2) ]. Now find the normal to (P2 - P1) [one normal of a vector (x,y) is the vector (-y,x)], and divide this by its length to get a unit vector N. Then you know Q must lie on the line starting at R with vector N: that is, Q = R + s*N, for some s. And you can find s by considering the right-angled triangle P1 R Q, which has hypotenuse R1, one side |R - P1| [ = R1 |P1-P2| / (R1+R2)] and the other side s. Using pythagoras, you can find s and thus Q. In untested actionScript (although I'd recommend making or finding a vector object that handles all the boring vector functions for you!): function findIntersection (p1, p2, r1, r2) { // p1 and p2 should be points such as {x:1, y:2} var p1p2 = vectorBetween(p2,p1) var dist = mag(p1p2) var sSquared = 1 - dist / (r1+r2) if (sSquared<0) {return "no such point"} var r = vectorSum(scalarMult(r2/(r1+r2),p1), scalarMult(r1/(r1+r2),p2)) var n = scalarMult(1/dist, normalVector(p1p2)) var s = r1 * math.sqrt(sSquared) return vectorSum(r, scalarMult(s, n)) } function vectorSum (a, b) { return {x: a.x+b.x, y: a.y+b.y} } function scalarMult (t, v) { return {x: t*v.x, y: t*v.y} } function mag (v) { return Math.sqrt(v.x*v.x + v.y*v.y) } function vectorBetween (a, b) { return {x:b.x - a.x, y: b.y - a.y} } function normalVector (v) { return {x: -v.y, y:v.x} } HTH Danny ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Math question: find coordinates of a point
I'd already found the solution where you'd rotate the triangle until it's base is horizontal, but unfortunately i know absolutely nothing about matrices. Seems like an interesting subject, mathematically rotating shapes is quite a useful skill. Couldn't i adapt the 'circle-method' to AS? No idea how i'd figure out the equation of these circles, but it should be possible, since i've got their centre and their radius. Thanks for the help so far, now i definitely now i need to get cozy with matrices, however much i'm fearing the subject On 12/27/05, Alan Shaw <[EMAIL PROTECTED]> wrote: > > On 12/26/05, Toon Van de Putte <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I've got a math question: > > > > How can i find the x,y coordinates of a point at a known equal distance > > from > > two other, known, points? > > > Well if it is strictly a math question the most straightforward way > might be analytic: solve the system of two equations > for the circles of radius d about the two points, as shown at > http://www.ping.be/~ping1339/circle.htm#Intersection-points- > > But I guess you might be wanting to find a code solution. I think > I have an idea: > > Use matrix operations to rotate the line connecting P1 and P2 > to horizontal and translate it to the X axis with midpoint at the > origin. Concat these operations into a single Matrix. > > The desired point(s) will now be found on the y axis with ordinate > equal to + or - sqrt(d * d - x * x), where d is your desired distance > and x is the current transformed abscissa of P2 (if d >= x that is). > > The invert the matrix and apply it to the points you found. > > What do you think? > > -A > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- Toon Van de Putte ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Math question: find coordinates of a point
On 12/26/05, Toon Van de Putte <[EMAIL PROTECTED]> wrote: > > Hi, > > I've got a math question: > > How can i find the x,y coordinates of a point at a known equal distance > from > two other, known, points? Well if it is strictly a math question the most straightforward way might be analytic: solve the system of two equations for the circles of radius d about the two points, as shown at http://www.ping.be/~ping1339/circle.htm#Intersection-points- But I guess you might be wanting to find a code solution. I think I have an idea: Use matrix operations to rotate the line connecting P1 and P2 to horizontal and translate it to the X axis with midpoint at the origin. Concat these operations into a single Matrix. The desired point(s) will now be found on the y axis with ordinate equal to + or - sqrt(d * d - x * x), where d is your desired distance and x is the current transformed abscissa of P2 (if d >= x that is). The invert the matrix and apply it to the points you found. What do you think? -A ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders