(Keeps Hive Alive)
The Hive Workshop
 Remember Me?
 Register FAQ Members List Calendar Mark Forums Read

 Miscellaneous Tutorials Warcraft III tutorials that do not fit into any other category. Read the Rules before posting.

 05-22-2011, 02:51 AM #1 (permalink) Nestharus User     Join Date: Jul 2007 Posts: 4,909 Spherical Coordinates The spherical coordinate system maps points relative to an origin given two angles and a distance. What makes this different from the Cartesian coordinate system is that rather than defining a point by its x,y,z distance from the origin, it defines a point by the magnitude of an x,y,z point and two angles (magnitude being distance). The magnitude is defined as ||p|| or ||r|| = SquareRoot(x*x+y*y+z*z) Notice how it has 3 dimensions. The z just needs to be added in order to get that third dimension. The two angles define direction. In the polar coordinate system, one angle and a distance is needed. This angle is theta, which is how far around a circle a given point goes. Theta- Code: ```x = r*cos(theta) y = r*sin(theta) r = ||p|| = SquareRoot(x*x + y*y) tan(theta) = y/x``` Note that because z is 0, it doesn't do anything in the polar coordinate system. By adding a z, the magnitude expands and a second angle is needed, this angle being how far the point is from the northern z-axis (easier this way). The range of phi goes from 0 to pi, 0 being north and pi being south. In polar coordinates, phi is always pi/2. Equations are as follows Code: ```x = p*cos(theta)*sin(phi) y = p*sin(theta)*sin(phi) z = p*cos(phi) p = SquareRoot(x*x + y*y + z*z) r = SquareRoot(x*x + y*y) tan(theta) = y/x tan(phi) = r/z``` Angle Between Points (x0, y0, z0) and (x, y, z). (x0, y0, z0) would be the first point Code: ```where ----xd = x - x0 ----yd = y - y0 ----zd = z - z0 ----pd = SquareRoot(xd*xd + yd*yd + zd*zd) ----rd = SquareRoot(xd*xd + yd*yd) tan(theta) = yd/xd tan(phi) = rd/zd``` Distance between two 3D points Code: ```where ----xd = x - x0 ----yd = y - y0 ----zd = z - z0 ----pd = SquareRoot(xd*xd + yd*yd + zd*zd) distance = pd``` Jass: thetaBetween = Atan2((y - y0), (x - x0)) phiBetween = Atan2(SquareRoot((x - x0)*(x - x0) + (y - y0)*(y - y0)), z - z0) distanceBetween = SquareRoot((x - x0)*(x - x0) + (y - y0)*(y - y0) + (z - z0)*(z - z0)) More information can be found at these sites Last edited by Nestharus; 01-06-2013 at 02:54 AM.
Magtheridon96
JESUS MAN

Resource Moderator

Join Date: Dec 2008
Posts: 5,699

I put them in a library for you ^^
Jass:
library CoordUtils
// All the math done by Nestharus
// Compiled to one library by Magtheridon96
// I based it on locations, but it can be easily changed to work with coordinates :)
function GetDistance takes location v, location w returns real
local real xd=GetLocationX(w)-GetLocationX(v)
local real yd=GetLocationY(w)-GetLocationY(v)
local real zd=GetLocationZ(w)-GetLocationZ(v)
return SquareRoot(xd*xd+yd*yd+zd*zd)
endfunction

function GetPHI takes location v, location w returns real
return Atan2(GetDistance(v,w),GetLocationZ(w)-GetLocationZ(v))
endfunction

// Returns the theta in radians
function GetTHETA takes location v, location w returns real
return Atan2(GetLocationY(w)-GetLocationY(v),GetLocationX(w)-GetLocationX(v))
endfunction
endlibrary
__________________

BusyWithSchool

Join Date: Oct 2008
Posts: 8,526
shocks... spherical coords... I remember my last calculus subject... anyway, looks helpful...
__________________
 Projects Resources Sites ExtraFiles
 The Adiktuz Scrolls: Arzachel (0.4alpha 05/11/11) TAS: Alchemia [DEMO] TAS: Highlancer (map) TASCOne on Visual Basic Sub-Shops Tutorial RMVX Script

PurgeandFire
ʕ•͡ᴥ•ʔ﻿

Resource & Tutorial Moderator

Join Date: Nov 2006
Posts: 3,544
I wish there was a test map/demo code for this to show how to practically use it, but otherwise it is good knowledge.

~Approved.
__________________
Tutorials
 Systems

 06-14-2011, 12:42 PM #5 (permalink) Orcnet HIVE WARCHIEF™   Resource Moderator   Join Date: Jul 2010 Posts: 2,476 yes! the demo map is a must bro! this tut is so useful! good job! (: __________________
Magtheridon96
JESUS MAN

Resource Moderator

Join Date: Dec 2008
Posts: 5,699

If you create an API for this with functions like: ApplyVectorMovement(unit), this would definitely deserve being a sticky :D
__________________

Magtheridon96
JESUS MAN

Resource Moderator

Join Date: Dec 2008
Posts: 5,699

~Opened.
__________________

 01-08-2013, 10:49 AM #8 (permalink) Statharas I prefer Nagisa anyway!     Join Date: Jul 2008 Posts: 1,914 Bookmarked, cause damn, this is useful. __________________
Almia
Oh Data Structures <3

Join Date: Apr 2012
Posts: 3,004
Can that library made by Magtheridon use for dummy.mdx roll?

 Bookmarks

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are Off Refbacks are Off Forum Rules

All times are GMT. The time now is 10:48 AM.

 -- Low Graphics ---- Night Elf ---- Terran (Beta) Contact Us - The Hive Workshop - The Warcraft 3 Modding Site - Archive - Top