• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Maths Issue (Vectors & Coordinates)

Status
Not open for further replies.
Level 17
Joined
Sep 8, 2007
Messages
994
Hello there,

I'm having a little math issue over here which I can't solve,
so I hope some maths-lovers here could help me with it.

I need a formula that gives me the coordinates of a circle lying in a aslope plane, like this:
b41766825ab84031cb8e08d6382dd1fc.png


What I figured out so far is that a circle on a plane has this form:

X=M+ r·u·cos(t) + r·v·sin(t)

where M is the support vector,
u and v the vectors defining the plane which are orthogonal to each other,
r the radius.

I guess my problem is about finding the proper values vor the vectors u and v in order to make the plane aslope like that, because the values I'm trying don't deliver what I need.
I'm not even sure if the formula is correct for this matter...

To make this more coding related I added the map containing the calculation I got so far.
Right now I'm having a circle on a plane of two axis only, but I need to get the third axis involved somehow to make the plane aslope in order to make that dummy unit spin not only up-down and left-right, but also back-forth.

Would be grateful for your help! :)
 

Attachments

  • Spinnn.w3x
    16.7 KB · Views: 105
Ok we all know the formula of a cirlce. A = pi radius squared. To get the X coordinate, use cos(A), to get the Y coordinate use sin(A). Now we have a new dimension: Z. By looking a circle from it's side, you see a straight line (Y = bX). this formula can be written as Z = (slope - 90) times radius. if you slope points 90 degrees up, your z won't change at all. Now there is a catch, if look the circle from the top that is rotated around the x or z-axis, it should look like an oval. To make that happen, your new X will be X + cos(Z) and your new Y will be Y + sin(Z).
thus
X = X + cos(Z)
Y = Y + sin(Z)
OR
X = X + cos[(slope - 90) times radius]
Y = Y + sin[(slope - 90) times radius]

Now how do you get the slope? You actually has two slopes. one when you view the normal from the front and one where view the normal from the side. Use the front slope to calculate the x values and the side to calculate the y values. I haven't tested it yet so if it doesn't work, I hope I gave some insights to solve the problem. I will look into it if it doesn't work ^^ Good luck!
 
Level 17
Joined
Sep 8, 2007
Messages
994
Ok we all know the formula of a cirlce. A = pi radius squared. To get the X coordinate, use cos(A), to get the Y coordinate use sin(A). Now we have a new dimension: Z. By looking a circle from it's side, you see a straight line (Y = bX). this formula can be written as Z = (slope - 90) times radius. if you slope points 90 degrees up, your z won't change at all. Now there is a catch, if look the circle from the top that is rotated around the x or z-axis, it should look like an oval. To make that happen, your new X will be X + cos(Z) and your new Y will be Y + sin(Z).
thus
X = X + cos(Z)
Y = Y + sin(Z)
OR
X = X + cos[(slope - 90) times radius]
Y = Y + sin[(slope - 90) times radius]

Now how do you get the slope? You actually has two slopes. one when you view the normal from the front and one where view the normal from the side. Use the front slope to calculate the x values and the side to calculate the y values. I haven't tested it yet so if it doesn't work, I hope I gave some insights to solve the problem. I will look into it if it doesn't work ^^ Good luck!

A = pi radius squared is the area, nothing what I want here.
This is not exactly a solution for my problem (at least not completely, I guess), but thank you anyways. +rep
 
Level 7
Joined
Oct 19, 2015
Messages
286
Right now, you are not defining your plane with vectors, but with rotations. You essentially draw a circle in the xz plane and then rotate it around the z axis by the facing of the unit plus 90 degrees. If you did another rotation prior to that around the x axis you would get a sloped plane.

I don't know what kind of behaviour you expect from your circular motion, should the plane of rotation change and how?
 
Level 7
Joined
Oct 19, 2015
Messages
286
I edited your function so it rotates the particle on a sloped plane. I declared a bunch of local variables for better readability, you can optimize it yourself by inlining things where appropriate.
JASS:
function action takes nothing returns nothing
    local real angle = (GetUnitFacing(target))*bj_PI/180.0
    local real slope = (45.0)*bj_PI/180.0
    // precompute the trigonometric functions
    // so we don't have to calculate the same thing multiple times
    local real cosa = Cos(angle)
    local real sina = Sin(angle)
    local real coss = Cos(slope)
    local real sins = Sin(slope)
    //circle on xy plane
    local real x = Cos(radians) * radius
    local real y = Sin(radians) * radius
    local real z = 0.0
    //rotation around y axis
    // since z is 0 this simplifies things,
    // coss and sins are used only once so we could inline them
    local real x1 = x * coss
    local real y1 = y
    local real z1 = x * sins
    //rotation around z axis
    set x = x1*cosa - y1*sina
    set y = x1*sina + y1*cosa
    set z = z1
    
    set radians = ModuloReal(radians +speed,2*bj_PI)
    call SetUnitX(dummy,         (GetUnitX(target) + xoffset)       + x)
    call SetUnitY(dummy,         (GetUnitY(target))                 + y)
    call SetUnitFlyHeight(dummy, (height)                           + z,0)
endfunction

You also need to account for the terrain height difference between the positions of target and dummy, right now it works correctly only because you're testing it on flat ground.
 
Level 17
Joined
Sep 8, 2007
Messages
994
I edited your function so it rotates the particle on a sloped plane. I declared a bunch of local variables for better readability, you can optimize it yourself by inlining things where appropriate.
JASS:
function action takes nothing returns nothing
    local real angle = (GetUnitFacing(target))*bj_PI/180.0
    local real slope = (45.0)*bj_PI/180.0
    // precompute the trigonometric functions
    // so we don't have to calculate the same thing multiple times
    local real cosa = Cos(angle)
    local real sina = Sin(angle)
    local real coss = Cos(slope)
    local real sins = Sin(slope)
    //circle on xy plane
    local real x = Cos(radians) * radius
    local real y = Sin(radians) * radius
    local real z = 0.0
    //rotation around y axis
    // since z is 0 this simplifies things,
    // coss and sins are used only once so we could inline them
    local real x1 = x * coss
    local real y1 = y
    local real z1 = x * sins
    //rotation around z axis
    set x = x1*cosa - y1*sina
    set y = x1*sina + y1*cosa
    set z = z1
    
    set radians = ModuloReal(radians +speed,2*bj_PI)
    call SetUnitX(dummy,         (GetUnitX(target) + xoffset)       + x)
    call SetUnitY(dummy,         (GetUnitY(target))                 + y)
    call SetUnitFlyHeight(dummy, (height)                           + z,0)
endfunction

You also need to account for the terrain height difference between the positions of target and dummy, right now it works correctly only because you're testing it on flat ground.

Thanks a lot! :) +rep
 
Status
Not open for further replies.
Top