Coordinate problem

Reaction score
456
JASS:
    function RotatePointAroundPoint takes integer point1, integer point2, real xAngle, real yAngle, real zAngle returns nothing
        local Point p1 = point1
        local Point p2 = point2
        local real angle
        local real radius = GetDistanceBetweenPoints(p1, p2)

        set angle = Atan2(p2.y - p1.y, p2.x - p1.x) + zAngle
        set p1.x = p2.x + radius * Cos(angle)
        set p1.y = p2.y + radius * Sin(angle)
    endfunction

So you have to care only about the last three lines. Others work just fine.

The point p1 is moved around the p2. It does not work properly, because it flips the point p1 from side to side.. Possible solutions?
 
Reaction score
456
>You sure about this?
It seems very logical to me, as I am rotating p1 around p2.

>If nothing else, the "bj" multiplications aren't needed.
True.
 
C

Chindril

Guest
Atan2 returns the angle in radian, so if zAngle contains 12 degree, you have to transform it using

... + (zAngle * bj_DEGTORAD) (or using Deg2Rad() function)

- Chindril
 

SerraAvenger

Cuz I can
Reaction score
234
JASS:
function TurnPointArroundLoc takes location toturn , location turnpoint, real angle returns location
    local real turnPointX        = GetLocationX( turnpoint )
    local real turnPointY        = GetLocationY( turnpoint )
    local real deltaX            = GetLocationX( toturn    ) - turnPointX
    local real deltaY            = GetLocationY( toturn    ) - turnPointX
    local real newX
    local real newY
    
    local real euclideanDistance = SquareRoot  ( deltaX * deltaX + deltaY * deltaY )
    local real newAngle
    if deltaX != 0 then
        set newAngle = Atan( deltaY / deltaX ) + angle * bj_DEGTORAD
        if deltaX < 0 then
            set newAngle = newAngle + bj_PI
        endif
    elseif deltaY > 0 then
        set newAngle = bj_PI / 2   + angle * bj_DEGTORAD
    elseif deltaY < 0 then
        set newAngle = 1.5 * bj_PI + angle * bj_DEGTORAD
    else
        set newAngle = 0
    endif
    set newX = Cos( newAngle ) * euclideanDistance 
    set newY = Sin( newAngle ) * euclideanDistance 
    call RemoveLocation( toturn )
    return Location( turnPointX + newX , turnPointY + newY )
endfunction

would that work?
Just change the location implementation with your point implementation : )
 
Reaction score
456
@Chindril
That part has been taken care of already.

@SerraAvenger
That works perfectly. Thanks :thup:! How should I modify that to make it work for x-axis rotation and y-axis rotation?
 

SerraAvenger

Cuz I can
Reaction score
234
@Chindril
That part has been taken care of already.

@SerraAvenger
That works perfectly. Thanks :thup:! How should I modify that to make it work for x-axis rotation and y-axis rotation?

Basically, it works the same way. Just with the difference that you need to change some of the names. I'll write an implementation of that for you that will allow turning arround any axis ; )
 
Reaction score
456
>Just with the difference that you need to change some of the names.
I tried this, but the results were.. how to say.. unexpected?

>I'll write an implementation of that for you that will allow turning arround any axis ; )
That'd be great, as I really suck at this kind of math :). I will credit you for this =).
 

SerraAvenger

Cuz I can
Reaction score
234
JASS:
struct point
    real x
    real y
    real z
    static method create takes real x, real y, real z returns point
        local point new = point.allocate()
        new.x = x
        new.y = y
        new.z = z 
        return new
    endmethod
            
    method rotate takes point fixpoint, real zenith, real azimuth returns nothing
        local real deltaX = fixpoint.x - .x
        local real deltaY = fixpoint.y - .y
        local real deltaZ = fixpoint.z - .z
        local real euclideanDist = SquareRoot( deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ )
        local real newZenith
        local real newAzimuth
        
        // new Zenith
        if deltaX != 0 then
            set newZenith = Acos( fixpoint.z / euclideanDist ) + zenith * bj_DEGTORAD
            if deltaX < 0 then
                set newZenith = newZenith + bj_PI
            endif
        elseif deltaY > 0 then
            set newZenith = 0.5 * bj_PI + zenith * bj_DEGTORAD
        elseif deltaY < 0 then
            set newZenith = 1.5 * bj_PI + zenith * bj_DEGTORAD                                                                
        else
            set newZenith = 0
        endif

        // new Azimuth
        if deltaZ != 0 then
            set newAzimuth = Atan( deltaY / deltaZ ) + azimuth * bj_DEGTORAD
            if deltaZ < 0 then
                set newAzimuth = newAzimuth + bj_PI
            endif
        elseif deltaZ > 0 then
            set newAzimuth = 0.5 * bj_PI + azimuth * bj_DEGTORAD
        elseif deltaZ < 0 then
            set newAzimuth = 1.5 * bj_PI + azimuth * bj_DEGTORAD
        else
            set newAzimuth = 0
        endif
        
        set .x   = fixpoint.x + euclideanDist * Sin( newZenith ) * Cos( newAzimuth )
        set .y   = fixpoint.y + euclideanDist * Sin( newZenith ) * Sin( newAzimuth )
        set .z   = fixpoint.z + euclideanDist * Cos( newZenith )
    endmethod
endstruct


This is what I came up whith, but I am not sure if this works 100% becouse I haven't tested it yet. Please test it and tell me if it works then : )

EDIT: Fixed Typo in the code
 

SerraAvenger

Cuz I can
Reaction score
234
That does not work :p.. and you misspelled azimuth ^^ (oh.. you fixed)

hm, too bad...
I had forgotten to reglobalise the new values
Code:
        set .x   = fixpoint.x + euclideanDist * Sin( newZenith ) * Cos( newAzimuth )
        set .y   = fixpoint.y + euclideanDist * Sin( newZenith ) * Sin( newAzimuth )
        set .z   = fixpoint.z + euclideanDist * Cos( newZenith )
try it again with these x,y and z values
If it still does not work, I'll have a closer look onto my code 2mrrw
 

SerraAvenger

Cuz I can
Reaction score
234
JASS:
struct point
    real x
    real y
    real z
    static method create takes real x, real y, real z returns point
        local point new = point.allocate()
        new.x = x
        new.y = y
        new.z = z
        return new
    endmethod
           
    method rotate takes point fixpoint, real zenith, real azimuth returns nothing
        local real deltaX = fixpoint.x - .x
        local real deltaY = fixpoint.y - .y
        local real deltaZ = fixpoint.z - .z
        local real euclideanDist = SquareRoot( deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ )
        local real newZenith
        local real newAzimuth
       
        // new Zenith
        
        set newZenith = Acos( deltaZ / euclideanDist ) + zenith * bj_DEGTORAD
        

        // new Azimuth
        if deltaZ != 0 then
            set newAzimuth = Atan( deltaY / deltaZ ) + azimuth * bj_DEGTORAD
            if deltaZ < 0 then
                set newAzimuth = newAzimuth + bj_PI
            endif
        elseif deltaZ > 0 then
            set newAzimuth = 0.5 * bj_PI + azimuth * bj_DEGTORAD
        elseif deltaZ < 0 then
            set newAzimuth = 1.5 * bj_PI + azimuth * bj_DEGTORAD
        else
            set newAzimuth = 0
        endif
       
        set .x   = fixpoint.x + euclideanDist * Sin( newZenith ) * Cos( newAzimuth )
        set .y   = fixpoint.y + euclideanDist * Sin( newZenith ) * Sin( newAzimuth )
        set .z   = fixpoint.z + euclideanDist * Cos( newZenith )
    endmethod
endstruct

Might this work?
 
Reaction score
456
Nope. :s

untitled1533.png

Makes it just flip from side to side, but not circle in any direction at all.
 

SerraAvenger

Cuz I can
Reaction score
234
Hm with my newest implementation, the turning arround Z-axis works perfectly...

I just don't get why the orbital angle does not work : (

JASS:
   method rotate takes point fixpoint, real zenith, real azimuth returns nothing
        local real deltaX = .x - fixpoint.x
        local real deltaY = .y - fixpoint.y
        local real deltaZ = .z - fixpoint.z
        local real euclideanDist = SquareRoot( deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ )
        local real d2Distance    = SquareRoot( deltaX * deltaX + deltaY * deltaY )
        local real newZenith
        local real newAzimuth
        
        // new Zenith    
        if deltaZ != 0 then
            set newZenith = Atan( d2Distance / deltaZ ) + zenith * bj_DEGTORAD
            if deltaZ < 0 then
                set newZenith = newZenith + bj_PI
            endif
        elseif d2Distance > 0 then
            set newZenith = 0.5 * bj_PI + zenith * bj_DEGTORAD
        elseif d2Distance < 0 then
            set newZenith = 1.5 * bj_PI + zenith * bj_DEGTORAD
        else    
            set newZenith = 0
        endif

        // new Azimuth
        if deltaX != 0 then
            set newAzimuth = Atan( deltaY / deltaX ) + azimuth * bj_DEGTORAD
            if deltaX < 0 then
                set newAzimuth = newAzimuth + bj_PI
            endif
        elseif deltaY > 0 then
            set newAzimuth = 0.5 * bj_PI + azimuth * bj_DEGTORAD
        elseif deltaY < 0 then
            set newAzimuth = 1.5 * bj_PI + azimuth * bj_DEGTORAD
        else
            set newAzimuth = 0
        endif
        
        set .x   = euclideanDist * Sin( newZenith ) * Cos( newAzimuth ) // d2Distance * Cos( newAzimuth )
        set .y   = euclideanDist * Sin( newZenith ) * Sin( newAzimuth ) // d2Distance * Sin( newAzimuth )
        set .z   = euclideanDist * Cos( newZenith )
    endmethod
 

SerraAvenger

Cuz I can
Reaction score
234
For me both of them work pretty weirdly.

with a zenite of 0, the azimuth works perfectly.
There are, however, even stranger problems.
When both of the points have the same X and Y coordinate, there is a division by 0 error.
The only two divisions are
Atan( d2Distance / deltaZ ) and Atan( deltaY / deltaX ). However, I wrote that the second division will only be executed when deltaX != 0.
It's really weird... Might it be that this strange behavior is a JASS symptome?
 

Builder Bob

Live free or don't
Reaction score
249
JASS:
    function RotatePointAroundPoint takes integer point1, integer point2, real xAngle, real yAngle, real zAngle returns nothing
        local Point p1 = point1
        local Point p2 = point2
        local real angle
        local real radius = GetDistanceBetweenPoints(p1, p2)

        set angle = Atan2(p2.y - p1.y, p2.x - p1.x) + zAngle
        set p1.x = p2.x - radius * Cos(angle)
        set p1.y = p2.y - radius * Sin(angle)
    endfunction


Subtract instead of adding on the two last lines when you set the p1.x and p1.y
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top