what you can additionaly do is using the absolute values: var ad:Number = Math.abs(v1sq - v0sq); i don't know if in your case you get negative values, but it might help anyways ;)
cheers On 25 Mrz., 12:57, Manic <mar...@graphicfilth.com> wrote: > oops, there's an error in that code, it should read var > pointing:Number = Math.atan(op/ad); > > On Mar 25, 11:51 am, Manic <mar...@graphicfilth.com> wrote: > > > Cheers for the reply, it's helped me a lot, in fact it feels so close > > now I can almost taste it. > > > Thing is, its not quite getting the maths right somehow, here's what > > it looks like; > > >http://graphicfilth.com/uncommon/bin-release/uncommon.html > > > as you can see, the arrows are mostly hanging around the top and not > > pointing from the right place. > > > here's the code that I've got; > > > var myArr:Mesh = this.getChildByName(peep.name+"arrow") as Mesh; > > > //we want to make the arrows live on the outside of the band icon, so > > we need to do some trig to get an angle > > //then move it to the outside of the icon along that angle > > > //opposite > > var op:Number = peep.scenePosition.y-scenePosition.y; > > > var v1sq:Number = Math.sqrt > > ((peep.scenePosition.x*peep.scenePosition.x) + > > (peep.scenePosition.z*peep.scenePosition.z)); > > var v0sq:Number = Math.sqrt((scenePosition.x*scenePosition.x) + > > (scenePosition.z*scenePosition.z)); > > //adjacent > > var ad:Number = v1sq - v0sq; > > > //Hopefully the angle > > var pointing:Number = Math.atan(op/-ad); > > > //make sure its not gone wrong > > if(!isNaN(pointing)){ > > myArr.vertices[0].adjust(Math.sin(pointing)*75,0,Math.cos(pointing) > > *75); > > myArr.vertices[1].adjust(myArr.vertices[0].x+5,0,myArr.vertices[0].z > > +5);} > > > //place last vert at the band member > > myArr.vertices[2].adjust(peep.scenePosition.x-scenePosition.x, > > > > scenePosition.z-peep.scenePosition.z, > > > > peep.scenePosition.y-scenePosition.y); > > > I'm currently trying to swap numbers around a bit, for some reason > > (possibly due to a rotation) my y/z coords seem to have gotten a bit > > garbled, although so far I've only managed to generate variations on > > the same broken theme. > > > I suppose it's also possible that my placement code is wrong. > > > Thanks again for the help, > > > Martin > > > On Mar 24, 2:13 pm, "pure....@googlemail.com" > > > <pure....@googlemail.com> wrote: > > > this is how i would do it: > > > first decide "what angle" i want to get, because there is more than > > > 1angle between two points in a 3-dimensional system > > > i assume you want the gradient-angle, so you have to eliminate the 3rd > > > koordinate: > > > x/y/z; x1/y1/z1 -> > > > _distX = ( Math.sqrt( x1² + z1² ) - ( Math.sqrt( x² + z² ) ) > > > _distY = y1 - y > > > > now can continue with: angle = Math.atan ( _distY / _distX ) > > > > maybe this helps you a little bit, not sure if that is excactly what > > > you wanted > > > > cheers olsn > > > > On 24 Mrz., 14:18, Manic <mar...@graphicfilth.com> wrote: > > > > > Hi, > > > > > I'm trying to find the angle between two Number3Ds, everything I've > > > > tried so far hasn't worked, I've had a go with using the screen > > > > position, the scene position, the relative positions... everything. > > > > > I want to make the large end of the arrows sit around the outside of > > > > the striped box, forming a sort of halo around it. > > > > >http://graphicfilth.com/uncommon/bin-release/uncommon.html > > > > > Here's what I understand so far... > > > > > The arrows are created as children of the main box, so vertex 0 is at > > > > 0,0,0 while vertex 2 is assigned to the location of it's blue circle > > > > using this code; > > > > > theArrow.vertices[2].adjust(peep.scenePosition.x-scenePosition.x, > > > > scenePosition.z-peep.scenePosition.z, peep.scenePosition.y- > > > > scenePosition.y); > > > > > Now, I don't know why this code works, in my mind it's wrong, but it > > > > does work, so I guess I'm wrong. > > > > > So, if I'm working using relative coordinates from the Arrow, I should > > > > just be able to use the location of Vertex 2 and drop that into Trig, > > > > something like; > > > > > angle = Math.atan(theArrow.vertices[2].y/theArrow.vertices[2].x) > > > > > then use that angle to plot the other 2 vertices around the center of > > > > the main object. > > > > > However it never returns accurate results, I've tried with every > > > > possible combination of x/y/z over x/y/z from the coords, but nothing > > > > seems to work. > > > > > I'm tearing my hair out here, because I'm sure I've got the principle, > > > > but not the execution. > > > > > Thanks in advance > > > > > Martin