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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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