[Log in / Register]
| News | Chat | Pastebin | Donations | Tutorials | Rules | Forums |
| Maps | Skins | Icons | Models | Spells | Tools | Jass | Packs | Hosted Projects | Starcraft II Modding | Starcraft II Resources | Galaxy Wiki |
(Keeps Hive Alive)
Go Back   The Hive Workshop > Warcraft III Modding > WarCraft III Tutorials > Miscellaneous Tutorials


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

Reply
 
Thread Tools
Old 05-22-2011, 02:51 AM   #1 (permalink)
Registered User Nestharus
User
 
Nestharus's Avatar
 
Join Date: Jul 2007
Posts: 4,909
Nestharus has disabled reputation
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.
Nestharus is offline   Reply With Quote
Old 05-22-2011, 12:54 PM   #2 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,699
Magtheridon96 has a brilliant future (1809)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
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

    // Returns angle in radians
    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
__________________
Magtheridon96 is offline   Reply With Quote
Old 05-28-2011, 11:31 PM   #4 (permalink)
Forum Moderator PurgeandFire
ʕ•͡ᴥ•ʔ
 
PurgeandFire's Avatar
Resource & Tutorial Moderator
 
Join Date: Nov 2006
Posts: 3,544
PurgeandFire has much of which to be proud (1096)PurgeandFire has much of which to be proud (1096)PurgeandFire has much of which to be proud (1096)PurgeandFire has much of which to be proud (1096)PurgeandFire has much of which to be proud (1096)
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.
PurgeandFire is offline   Reply With Quote
Old 06-14-2011, 12:42 PM   #5 (permalink)
Forum Moderator Orcnet
HIVE WARCHIEF™
 
Orcnet's Avatar
Resource Moderator
 
Join Date: Jul 2010
Posts: 2,476
Orcnet is a splendid one to behold (842)Orcnet is a splendid one to behold (842)Orcnet is a splendid one to behold (842)Orcnet is a splendid one to behold (842)Orcnet is a splendid one to behold (842)
yes! the demo map is a must bro! this tut is so useful! good job! (:
__________________
Orcnet is online now   Reply With Quote
Old 06-19-2011, 01:56 AM   #6 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,699
Magtheridon96 has a brilliant future (1809)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
If you create an API for this with functions like: ApplyVectorMovement(unit), this would definitely deserve being a sticky :D
__________________
Magtheridon96 is offline   Reply With Quote
Old 01-06-2013, 02:13 AM   #7 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,699
Magtheridon96 has a brilliant future (1809)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
~Opened.
__________________
Magtheridon96 is offline   Reply With Quote
Old 01-08-2013, 10:49 AM   #8 (permalink)
Registered User Statharas
I prefer Nagisa anyway!
 
Statharas's Avatar
 
Join Date: Jul 2008
Posts: 1,914
Statharas is just really nice (293)Statharas is just really nice (293)Statharas is just really nice (293)Statharas is just really nice (293)Statharas is just really nice (293)
Bookmarked, cause damn, this is useful.
__________________


Statharas is offline   Reply With Quote
Old 04-09-2013, 06:55 AM   #9 (permalink)
Registered User Almia
Oh Data Structures <3
 
Almia's Avatar
 
Join Date: Apr 2012
Posts: 3,004
Almia is a name known to all (645)Almia is a name known to all (645)
Can that library made by Magtheridon use for dummy.mdx roll?
Almia is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

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 Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


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





Powered by vBulletin
Copyright 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.1 PL2
Copyright © Ralle