Increasing distance from origin

Software: Away3D 4.x

Avatar
maddog, Sr. Member
Posted: 22 October 2011 07:09 PM   Total Posts: 118

I am playing around with increasing and decreasing objects distance form origin while maintaining angle of departure. I split a sphere into peaces and want the pieces to increase and decrease their distance from origin. However I have never been a math wiz so I am having a hard time raping my head around the math. Anyone have any ideas of equation I should look at for this or does away already have a function to implement this?
thanks for any Ideas : )

   

Somokon, Member
Posted: 22 October 2011 09:45 PM   Total Posts: 75   [ # 1 ]

This function should do it.

function addDistance(point:Vector3D, d:Number):Vector3D {
   
    
var r:Number = Math.sqrt(point.x*point.x + point.z*point.z + point.y*point.y);
    var 
theta:Number = Math.acos(point.y / r);
    var 
phi:Number = Math.atan2(point.z, point.x);
   
    
r += d;
   
    return new 
Vector3D(r*Math.sin(theta)*Math.cos(phi), r*Math.cos(theta), r*Math.sin(theta)*Math.sin(phi));
} 

It converts to spherical coordinates, adds the distance, then converts it back to an (x,y,z) Cartesian point.

   

Avatar
maddog, Sr. Member
Posted: 22 October 2011 11:46 PM   Total Posts: 118   [ # 2 ]

Thanks for the help. It projects parts at a constant distance, but not angle like I want unless I am still doing it wrong. this is the code so far.

function addDistance(point:Vector3D, d:Number):Vector3D {
      
var r:Number = Math.sqrt(point.x*point.x + point.z*point.z + point.y*point.y);
      var 
theta:Number = Math.acos(point.y / r);
      var 
phi:Number = Math.atan2(point.z, point.x);
      
r += d;
      return new 
Vector3D(r*Math.sin(theta)*Math.cos(phi), r*Math.cos(theta), r*Math.sin(theta)*Math.sin(phi));
  
}  
  
  
  
function onOverModel(event:MouseEvent3D):void {
   
    Mesh
(event.object).mouseEnabled=false;
    var 
current:Vector3D = new Vector3D(event.target.position.x, event.target.position.y, event.target.position.z);
    var 
moveHere:Vector3D = addDistance(current, -2);
    
    
TweenNano.to(event.object, .2, {x:moveHere.x, y:moveHere.y ,z:moveHere.z, onComplete:returnMe});
    function  
returnMe(){
     TweenNano
.to(event.object, .5, {x:current.x, y:current.y ,z:current.z, onComplete:function(){Mesh(event.object).mouseEnabled=true;}});
    
}
   
  } 

Here is what happens with that code:
http://www.lukascanoe.com/away3d/IsoSphere.html

   

Avatar
maddog, Sr. Member
Posted: 22 October 2011 11:46 PM   Total Posts: 118   [ # 3 ]

——

   

Avatar
80prozent, Sr. Member
Posted: 23 October 2011 01:06 AM   Total Posts: 430   [ # 4 ]

hi

i think what you need to do is to move the verts along their normals.

you find more info about this in this thread:

http://away3d.com/forum/viewthread/979/

hope that helps

80

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
maddog, Sr. Member
Posted: 23 October 2011 01:44 AM   Total Posts: 118   [ # 5 ]

I think my problem was the sphere was not aligned right to origin. I took it back into blender and realigned origin to mesh and it worked.

Some what working

I have notice a glitch where sometime pieces lose there mouse enabled status and no longer are able to be clicked. any ideas?

   

John Brookes, Moderator
Posted: 23 October 2011 01:00 PM   Total Posts: 732   [ # 6 ]

You shouldn’t need to mess with spherical coords
If its points on the surface of a sphere located at the origin all you have to do is multiply the position of that point.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X