getangle3d how to do that?

Blitz3D Forums/Blitz3D Beginners Area/getangle3d how to do that?

Pakz(Posted 2014) [#1]
I was wondering if anyone knows how to get the angle between 2 points in 3d space. I want to create a cave system and need to follow paths in a array to carve out.

I have read that you might need two angle values for 3d space. But I have also found one function that returns one angle. And how do you move them once you got the angle.

Is this how it is done?
x=x+cos(a)*1
y=y+sin(a)*1
z=z+cos(a)*1

I have been looking around but I have not gotten far.


This is a function but it only returns 180



This is a function I have converted but it needs the pow command.


Help is appreciated


Krischan(Posted 2014) [#2]
I am not quite sure, but I assume that you're searching for these two commands?

DeltaPitch#(src_entity,dest_entity)
DeltaYaw#(src_entity,dest_entity)

Moving could be done with PointEntity and then MoveEntity along the Z axis if using entities only. For vector transformation you should look at the TFormVector command or the AlignToVector command.


stayne(Posted 2014) [#3]
Doesn't Pythagorean's theorum cover this?


Matty(Posted 2014) [#4]
The dot product can be used to find the angle between two vectors.

a.b = |a||b| cos (theta)

Simply rearrange to get theta.

Alternatively, if you wish to do it by letting blitz do the work for you then you could do it using pivots, tformvector, aligning the pivot and then retrieving the angles from entitypitch etc.


Kryzon(Posted 2014) [#5]
For 3D "look at" rotations you only need two axes, the pitch and yaw. The roll axis (z) won't make a difference.

If you know the 3D coordinates of two locations in space, you can get their difference and find the pitch and yaw for that difference.
As in physics, a "delta" is the target position minus the starting position.

dX# = targetX - sourceX
dY# = targetY - sourceY
dZ# = targetZ - sourceZ

RotateEntity( myEntity, VectorPitch( dX, dY, dZ ), VectorYaw( dX, dY, dZ ), 0, True )
;Provided that your entity is facing the +Z direction when under a null rotation.

EDIT: An alternative that should be faster, using the dX, dY and dZ from above...

AlignToVector( myEntity, dX, dY, dZ, 3, 0 )


Blitzplotter(Posted 2014) [#6]
I'm so looking forward to having the time to get my noggin around this thread ;)


Pakz(Posted 2014) [#7]
I am going to try this but havent done this yet. Can you not get two 2d angles for a 3d angle? One for x and y and one for y and z or so?
I also want to make homing missiles and need to turn by a step at a time.

I hate to have to experiment with the blitz 3d commands to build a map in a array. Setting up a graphics screen and then translating the coordinates to the array.

I need to get some motivation to do some experimenting :) I keep opening up the browser for other things :)


Pakz(Posted 2014) [#8]
I have got it working!! I figured that you needed two angles to move by in 3d space. I have made code where a cube moves towards another cube. When it gets there the destination is randomly changed and the cube moves towards that destination cube.

I have used a standard getangle function that I have put on the code archives in the homing missiles post.




Mikorians(Posted 2014) [#9]
Hm! My Rec2Polar function's much more complicated!
Have you tested your GetAngle function in every eventuality?
With negative values and values greater than 360 degrees?
I'd be interested.


Pakz(Posted 2014) [#10]
The 3D angle is the same as the 2D angle except for 3D you use y for the z for the second angle. I have not tested a lot. I think it is pretty solved here.


Mikorians(Posted 2014) [#11]
I'll check it out and post my results here.
My app goes through -some- convolutions.


Mikorians(Posted 2014) [#12]
For everyone else to know (FYI) - YES, it does work WELL.
What a nice simple function! Thanks!