Skip to content

Instantly share code, notes, and snippets.

@arifbalik
Created February 26, 2021 14:25
Show Gist options
  • Save arifbalik/d9fee7a56803c37c81aad1a106b15968 to your computer and use it in GitHub Desktop.
Save arifbalik/d9fee7a56803c37c81aad1a106b15968 to your computer and use it in GitHub Desktop.
Collision Avoidance
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#define REC_WIDTH 130
#define REC_HEIGHT 85
#define CIRCLE_RAD 90
float circle_control(float x, float y, float cx,float cy, float radius) {
double distance;
distance = sqrt(pow(((x - 20)-cx),2) + pow((y-cy),2));
printf("Circle %s, distance=%f\n", (distance <= radius) ? "passed" : "failed", distance);
return distance <= radius;
}
float rectangle_control (float x, float y){
uint8_t res = x < REC_WIDTH && x > 0 && y > ((CIRCLE_RAD - REC_HEIGHT)/2) && y < (REC_HEIGHT + ((CIRCLE_RAD - REC_HEIGHT)/2));
printf("Rectangle %s\n", res ? "passed" : "failed");
return res;
}
float position_reachable(float x, float y, float z ){
return circle_control(x, y, 65, 45, CIRCLE_RAD) && rectangle_control(x, y);
}
int main(){
float x,y,z,cx,cy,radius;
printf("x,y,z sirayiyla girilmeli : ");
scanf("%f %f %f",&x,&y,&z);
//printf("Dairenin merkezinin capi giriniz : ");
radius = 90;
cx = 0;
cy = 0;
if(position_reachable(x,y,z)){
printf("Girilen degerler sinir icerisindedir...");
}
else{
printf("girilen degerler sinir icerisinde degildir. ");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment