Article View: comp.lang.c
Article #1828Re: [pic] avoidance problem
From: fir
Date: Tue, 24 Nov 2026 00:58
Date: Tue, 24 Nov 2026 00:58
234 lines
9866 bytes
9866 bytes
Ross Finlayson pisze:
> On 11/23/2026 03:23 PM, fir wrote:
>> fir pisze:
>>> fir pisze:
>>>> imagine you got a flyin ships in space (which may be treated as
>>>> spheres)
>>>> they got direction and forvard velocity, they may turn yaw/pitch also
>>>> slow down or accelerate... the yaw pitch slowdown/acceleraty is by
>>>> applying forces (yaw_force, pitch_force.. and so on, this force is
>>>> from 0.0 to 1.0 which is max, usualy max is applied and this force
>>>> gives increases some taw/pitch velocity but there is also damping)
>>>>
>>>> the problem is i need to vrite a good routine that would make good
>>>> result in avoiding
>>>>
>>>> the input is position, radius, direction, forward_velocity for both
>>>> participants (i mean for each ship i run it in the loop for any other
>>>> so it make pairs)
>>>>
>>>> what ai gives me not quite work and this is exampla how working with
>>>> ai look like, i need myself somewhat rationalize it to find good answer
>>>
>>>
>>>
>>> some idea come to me and ai - not to think in geometry (in which im
>>> not good) but just count a next point, count a next point if i would
>>> turn right, left , count a next point if i turn down, up , count next
>>> point if i speed up, down -- and chose the point which is most far to
>>> collision..thats great local simplicity though all those countings are
>>> sorta heavy
>>>
>>>
>>>
>>>
>>> void AvoidSphere(int i, float i_radius, float3 object_pos,float3
>>> object_velocity,float object_radius)
>>> {
>>> float3 object_next=add(object_pos,object_velocity);
>>>
>>> float avoid_radius=object_radius + i_radius + AVOID_DISTANCE;
>>>
>>> float3 to_object=sub(object_pos,bag[i].p.pos);
>>> float distance0=length(to_object);
>>>
>>> if(distance0>=avoid_radius) return;
>>>
>>> bag[i].is_avoiding+=1;
>>>
>>> /* Punkt, w którym statek znajdzie się bez żadnej dodatkowej
>>> siły. */
>>> float3 p0=PredictNextFrameObjectPosition(i,0,0,0,0,0,0);
>>> float best_distance=distance(p0,object_next);
>>>
>>> float best_yaw=0;
>>> float best_pitch=0;
>>> float best_forward=0;
>>>
>>> /* Lewo / prawo. */
>>> float3 p;
>>> float d;
>>>
>>> p=PredictNextFrameObjectPosition(i, 1,0,0,0,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=1; best_pitch=0;
>>> best_forward=0; }
>>> p=PredictNextFrameObjectPosition(i,-1,0,0,0,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=-1; best_pitch=0;
>>> best_forward=0; }
>>> p=PredictNextFrameObjectPosition(i,0, 1,0,0,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=1;
>>> best_forward=0; }
>>> p=PredictNextFrameObjectPosition(i,0,-1,0,0,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=-1;
>>> best_forward=0; }
>>>
>>> p=PredictNextFrameObjectPosition(i, 1,0,0,1,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=1; best_pitch=0;
>>> best_forward=1; }
>>> p=PredictNextFrameObjectPosition(i,-1,0,0,1,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=-1; best_pitch=0;
>>> best_forward=1; }
>>> p=PredictNextFrameObjectPosition(i,0, 1,0,1,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=1;
>>> best_forward=1; }
>>> p=PredictNextFrameObjectPosition(i,0,-1,0,1,0,0);
>>> d=distance(p,object_next);
>>> if(d>best_distance) { best_distance=d; best_yaw=0; best_pitch=-1;
>>> best_forward=1; }
>>>
>>>
>>> /* Wybieramy najlepszy ruch. */
>>> bag[i].yaw_force=best_yaw;
>>> bag[i].pitch_force=best_pitch;
>>> bag[i].forward_force=best_forward;
>>> }
>>>
>>>
>>>
>>> also there is case when ships could collide with more things they
>>> avoid one and just run stright into another and explode ;c
>>>
>>> i alos not sure if it behaves well in 1-1 collisions such things are
>>> quite hard to visually debug
>>
>> some addition to avoid the closest resolved part of problems
>>
>>
>>
>> int FindClosestColiding(int i,float* dist,int* n_colliding)
>> {
>> float ship_collision_radius=ShipRadius(i);
>> float closest_distance=1000000000.0f;
>> int closest=-1;
>>
>> *n_colliding=0;
>>
>> for(int j=0;j<bag_max;j++)
>> {
>> if(!bag[j].enabled) continue;
>> if(j==i) continue;
>>
>> float object_radius;
>>
>> if(bag[j].type=='ship' || bag[j].type=='play')
>> object_radius=ShipRadius(j);
>> else if(bag[j].type=='aste')
>> object_radius=AsteroidRadius(j);
>> else
>> continue;
>>
>> float d=distance(bag[i].p.pos, bag[j].p.pos);
>> float
>> collision_distance=ship_collision_radius+object_radius+AVOID_DISTANCE;
>>
>> if(d<collision_distance)
>> {
>> (*n_colliding)++;
>>
>> if(d<closest_distance)
>> {
>> closest_distance=d;
>> closest=j;
>> }
>> }
>> }
>>
>> *dist=closest_distance;
>>
>> return closest;
>> }
>>
>>
>> void AvoidCollisions(int i)
>> {
>> bag[i].is_avoiding=0;
>>
>> float distance;
>> int n_colliding;
>>
>> int j=FindClosestColiding(i,&distance,&n_colliding);
>>
>> if(j<0) return;
>>
>> bag[i].is_avoiding=n_colliding;
>>
>> float ship_collision_radius=ShipRadius(i);
>>
>> if(bag[j].type=='ship' || bag[j].type=='play')
>> AvoidSphere(i,ship_collision_radius,bag[j].p.pos,GetShipWholeVelocity(j),ShipRadius(j));
>>
>>
>> else if(bag[j].type=='aste')
>> AvoidSphere(i,ship_collision_radius,bag[j].p.pos,f3(0,0,0),AsteroidRadius(j));
>>
>>
>> }
>>
>>
>>
>> but how to deduce if it is right - red circle marks if the avoiding
>> routine is in work - finally the ship anyway colide
>>
>> what is seen on video (i got heavy drop of fps onvideo sometimes it
>> ahppen probably depent on hat i run in parralel and i forgot to close
>> some apps)
>>
>>
>> https://www.youtube.com/watch?v=DWJI_BO_IdM
>
> "Octrees" after "quadtrees" were already in the computer science
> literature circa 1990-ish (when Doom came out).
>
> Pyramidal/hierarchical vis-a-vis lattice accounts are pretty usual.
>
> Collision detection is a pretty hard problem, usually after bounding-boxes.
>
>
doesnt seem tpo hard (in simple version, optimisation for big amount of
coliding bodies may worry me) but there is a need to see it in simple way
its also unusually hard to debug by eyes..i got something but is that
good o r bad, i dont know..it seems to avoid some collisions but with
some will crash (maybe no wonder as it has limits to change speed but
maybe its bad becouse it could avoid in limits, hard to say...
yet sometimes those ships look like flyin in small radius circles which
is unwelcome, tooo
so i wouldnt say its to hard It's not particularly difficult, but it
does require some know-how like when hammering nails etc
its in some way interesting though - so i post the question in case
someone is boring
>
> Physics the mechanics' account still can't exactly explain "static
> torque", or why that since Galileo's laws say nothing about spinning
> bodies, there's room in the theory, then, that Magnus and Coriolis
> effects can't be added up to explain away ballistics, there's room
> in the data, for the whole "space-contraction-linear and
> space-contraction-rotational and inertial-systems where momentum is
> not conserved", about that nothing's ever exactly "equal & opposite"
> (though theories like as after Galileo's and Newton's are plenty
> good, or, "up to first, second, third orders").
>
>
>
Technical Details
Message-ID:
<11e2nfb$2d4c9$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11e2610$26vvs$1@dont-email.me> <11e2enj$2a9jv$1@dont-email.me> <11e2hti$2bco0$1@dont-email.me> <OOWcnaH3k4ySTpn2nZ2dnZfqn_adnZ2d@giganews.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: Re: [pic] avoidance problem Date: Tue, 24 Nov 2026 01:58:20 +0100 Organization: A noiseless patient Spider Lines: 234 Message-ID: <11e2nfb$2d4c9$1@dont-email.me> References: <11e2610$26vvs$1@dont-email.me> <11e2enj$2a9jv$1@dont-email.me> <11e2hti$2bco0$1@dont-email.me> <OOWcnaH3k4ySTpn2nZ2dnZfqn_adnZ2d@giganews.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 24 Nov 2026 00:58:20 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2527625"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+Zee71x+XRXDxs8z8o45r3Yq8n1rMpyM="; posting-host="6f20364f3e3a115eee9a426bf85039b2" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:RngrLXJ0W5qKqp/QS/AYXdQDAt0= sha256:w8nuK/XyFR6PMRx5bnS/k13CXJ0z8qNFotD7Tq4aIHU= sha1:srro4st0IWaTi/BrI6OvJmX1aGM= sha256:pJCT2lvbXPu98Xc2QBkIba/ZZDo/8OEo7ajoNv0cSng= In-Reply-To: <OOWcnaH3k4ySTpn2nZ2dnZfqn_adnZ2d@giganews.com>