Circle movement using vectors?

DonRoman

New Member
Reaction score
5
Hey, lately I've been trying to do some kind of projectile system for practice, however I always fail when it comes to doing a circle movement around a certain point in 3d.

Here what that means: I got a projectile thats moving into a specific area, now it should continue on a circular path. For all the movements I used vectors and I dont really want any trigonometric functions. I tried using the centripetal force towards the center but somehow i couldnt get it to work. :/

mv^2/r = m * a ; m = mass ; v = velocity = length of velocity vector; r = radius = length of vector between current location and center ; a = acceleration

I tried to calculate a as acceleration towards the center and add it to v but i failed :(

maybe someone of you got an idea ??
 

Trollvottel

never aging title
Reaction score
262
well i did some likely thing and have got no problems, would you show the part of the code pls?
 

DonRoman

New Member
Reaction score
5
Alright here it is, it probably just is some stupid mistake by me ...

also the code is not yet fully optimized :/

JASS:
library PS initializer Init uses PUI
//########################################################################

globals
    private constant real PERIODE = 0.03125
    private constant real MAX_SPEED = 1000 * PERIODE
    
    private real MAX_X
    private real MAX_Y
    private real MIN_X
    private real MIN_Y
    private timer TIMER = CreateTimer()
    private location TempLoc = Location(0,0)
    private vector GRAVITY
    private forcefield Field
endglobals
//=======================================================================
// Useful functions
//=======================================================================

private function GetTerrainZ takes real x, real y returns real
    call MoveLocation(TempLoc, x, y)
    return GetLocationZ(TempLoc)
endfunction

private function SafeX takes real x returns real
    if x > MAX_X then
        return MAX_X
    elseif x < MIN_X then
        return MIN_X
    endif
    return x
endfunction

private function SafeY takes real x returns real
    if x > MAX_Y then 
        return MAX_Y
    elseif x < MIN_Y then
        return MIN_Y
    endif
    return x
endfunction
//=======================================================================
// vector struct
//=======================================================================

struct vector
    real x
    real y
    real z
    
    static method create takes real x, real y, real z returns vector
        local vector v = vector.allocate()
        set v.x = x
        set v.y = y
        set v.z = z
        return v
    endmethod
    
    method declare takes real x, real y, real z returns nothing
        set .x = x
        set .y = y
        set .z = z
    endmethod
    
    method add takes vector v returns nothing
        set .x = .x + v.x
        set .y = .y + v.y
        set .z = .z + v.z
    endmethod
    
    method subtract takes vector v returns nothing
        set .x = .x - v.x
        set .y = .y - v.y
        set .z = .z - v.z
    endmethod
    
    method scale takes real x returns nothing
        set .x = .x * x
        set .y = .y * x
        set .z = .z * x
    endmethod
    
    method getLength takes nothing returns real
        return SquareRoot(.x * .x + .y * .y + .z * .z) 
    endmethod

    method getLengthSquare takes nothing returns real
        return .x * .x + .y * .y + .z * .z
    endmethod
    
    static method VectorBetweenPoints takes vector origin, vector point returns vector
        local vector v = vector.create(point.x - origin.x, point.y - origin.y, point.z - origin.z)
        return v
    endmethod
    
    method SetVectorBetweenPoints takes vector origin, vector point returns nothing
        set .x = point.x - origin.x
        set .y = point.y - origin.y
        set .z = point.z - origin.z
    endmethod
    
    static method GetPointDistanceSquare takes vector origin, vector point returns real
        local vector v = vector.create(point.x - origin.x, point.y - origin.y, point.z - origin.z)
        local real r   = v.x * v.x + v.y * v.y + v.z * v.z
        call v.destroy()
        return r
    endmethod
endstruct
//==========================================================================
// Begin of Projectile things
//==========================================================================

struct projectile
    unit u
    
    real mass
    
    vector position
    vector velocity
    vector acceleration
    vector forcefactor
    
    static group members = CreateGroup()
    static vector Helper
    
    //! runtextmacro PUI()
    
    static method create takes player q, integer id, real x, real y, real z, real speed, real angle, real zangle returns projectile
        local projectile p = projectile.allocate()
        set p.u = CreateUnit(q, id, x, y, angle)
        
        call UnitAddAbility(p.u, 'Amrf')
        call SetUnitFlyHeight(p.u, z - GetTerrainZ(x,y), 0)
        call UnitRemoveAbility(p.u, 'Amrf')
        
        set p.position     = vector.create(x,y,z)
        set p.velocity     = vector.create(Cos(angle * bj_DEGTORAD) * speed, Sin(angle * bj_DEGTORAD) * speed, Sin(angle * bj_DEGTORAD) * speed)
        set p.acceleration = vector.create(0,0,0)
        set p.forcefactor  = vector.create(0,0,0)
        //call p.acceleration.add(GRAVITY)
        call p.velocity.scale(PERIODE)
        call p.acceleration.scale(PERIODE)
        
        set projectile[p.u]  = p
        call GroupAddUnit(p.members, p.u)
        
        return p
    endmethod
    
    method execute takes nothing returns nothing
        local integer i = 1
        local vector helper
        local newField field
        
        set i = newField.count
        //call BJDebugMsg(I2S(newField.count))
        loop
            exitwhen i == 0
            set field = newField.Data<i>
            set helper = vector.VectorBetweenPoints(.position, field.position)
            if helper.getLengthSquare() &lt;= field.radius then
                call helper.scale(.velocity.getLengthSquare() / helper.getLengthSquare() * PERIODE)
                call BJDebugMsg(&quot;Velocity Before: &quot; + R2S(helper.getLength()))
            endif
            set i = i - 1
        endloop
        
        call BJDebugMsg(&quot;Velocity Before: &quot; + R2S(.velocity.getLength()))
        call .velocity.add(.acceleration)
        call BJDebugMsg(&quot;Velocity After: &quot; + R2S(.velocity.getLength()))
        call .position.add(.velocity)
        call .position.add(helper) // tried different things here
        
        set .position.x = SafeX(.position.x)
        set .position.y = SafeY(.position.y)
        
        call SetUnitX(.u, .position.x)
        call SetUnitY(.u, .position.y)
        call SetUnitFlyHeight(.u, .position.z - GetTerrainZ(.position.x, .position.y), 0)
        
        if .velocity.getLengthSquare() &gt; MAX_SPEED * MAX_SPEED then
            call .velocity.scale(MAX_SPEED / .velocity.getLength())
        endif
        
        call helper.destroy()
    endmethod
    
endstruct

//===========================================================================
// new forcefield
//===========================================================================
struct newField
    vector position
    real radius
    
    static newField array Data
    static integer count = 0
    
    static method create takes real x, real y, real z, real radius returns newField
        set .count = .count + 1
        set .Data[.count] = newField.allocate()
        set .Data[.count].position = vector.create(x,y,z)
        set .Data[.count].radius = radius
        return .Data[.count]
    endmethod
endstruct

//===========================================================================
private function GroupLoop takes nothing returns nothing
    local projectile p = projectile[GetEnumUnit()]
    call p.execute()
endfunction

private function Loop takes nothing returns nothing
    call ForGroup(projectile.members, function GroupLoop)
endfunction

private function Init takes nothing returns nothing
    call TimerStart(TIMER, PERIODE, true, function Loop)
    
    set MIN_X = GetRectMinX(bj_mapInitialPlayableArea)
    set MIN_Y = GetRectMinY(bj_mapInitialPlayableArea)
    set MAX_X = GetRectMaxX(bj_mapInitialPlayableArea)
    set MAX_Y = GetRectMaxY(bj_mapInitialPlayableArea)
    
    set GRAVITY = vector.create(0,0, -10)
    set projectile.Helper = vector.create(0,0,0)
    call newField.create(1000,1000, 1000, 10000)
endfunction
//########################################################################
endlibrary</i>
 

Viikuna

No Marlo no game.
Reaction score
265
My math skills usually fail me, but isnt it: a = (v*v) / r ?
 

darkbeer

Beer is Good!
Reaction score
84
ye and thats what i think he did here:

JASS:
call helper.scale(.velocity.getLengthSquare() / helper.getLengthSquare() * PERIODE)
 
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

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top