• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Intersection of 2 circles

kupo15

Member
I'm trying to find the intersection of two circles (I only need the bottom one or left one) and its obvious you need to do some different methods to solve it. I found this on a java site and it should be able to work here but I'm not not quite getting it to work? Has anyone done this before and can help out?

I was using this site
https://fypandroid.wordpress.com/2011/07/03/how-to-calculate-the-intersection-of-two-circles-java/

Code:
// scr_intersection(x1,y1,r1,x2,y2,r2);

var x1,y1,r1,x2,y2,r2;
x1 = argument0;
y1 = argument1;
r1 = argument2;
x2 = argument3;
y2 = argument4;
r2 = argument5;

var apart,d1,h;
apart = point_distance(x1,y1,x2,y2); // distance between two circles
d1 = (sqr(r1)-sqr(r2)+sqr(apart))/(2*apart);
h = sqrt(sqr(r1)-sqr(d1));

var x3,y3;
x3 = x1+(d1*(x2-x1))/apart;
y3 = y1+(y1*(y2-y1))/apart;

// intersection 1
var x4,y4;
x4 = x3+(h*(y2-y1))/apart;
y4 = y3-(h*(x2-x1))/apart;
 

kupo15

Member
I have a question that will make things a bit more complicated. How would I go about translating this so that it works for 3D where the y value is the z value? I got the variable substitutions in there and it works a little but I need to throw a lengthdir somewhere in there to account for the character's rotational angle. When he rotates the intersection point doesn't stay in the place

Code:
scr_intersection(x+lengthdir_x(left_arm_pos_x[1],dir-90),z+left_arm_pos_z[1],30,x+lengthdir_x(left_arm_pos_x[3],dir-90),z+left_arm_pos_z[3],30);
// [1] = shouder
// [3] = hand
Code:
/// scr_intersection(x1,y1,r1,x2,y2,r2);

// set elbow position
left_arm_pos_x[2] = x4;
left_arm_pos_z[2] = y4;

elbow_difference = left_arm_pos_x[2]-x;
Code:
// draw

// draw the left bicep
d3d_transform_stack_push();
d3d_transform_add_rotation_x(left_arm_rot_x[1]);
d3d_transform_add_rotation_y(left_arm_rot_y[1]);
d3d_transform_add_rotation_z(dir-90);
d3d_transform_add_translation(x+lengthdir_x(left_arm_pos_x[1],dir-90),y+lengthdir_y(left_arm_pos_x[1],dir-90)+left_arm_pos_y[1],z+left_arm_pos_z[1]);
d3d_model_draw(left_arm_model[1],0,0,0,left_arm_texture[1]);
d3d_transform_stack_pop();


// draw the left elbow
d3d_transform_stack_push();
d3d_transform_add_rotation_x(left_arm_rot_x[2]);
d3d_transform_add_rotation_y(left_arm_rot_y[2]);
d3d_transform_add_rotation_z(dir-90);
d3d_transform_add_translation(x+lengthdir_x(elbow_difference,dir-90),y+lengthdir_y(elbow_difference,dir-90),left_arm_pos_z[2]);
d3d_model_draw(left_arm_model[2],0,0,0,left_arm_texture[2]);
d3d_transform_stack_pop();

// draw the left hand
d3d_transform_stack_push();
d3d_transform_add_rotation_x(left_arm_rot_x[3]);
d3d_transform_add_rotation_y(left_arm_rot_y[3]);
d3d_transform_add_rotation_z(dir-90);
d3d_transform_add_translation(x+lengthdir_x(left_arm_pos_x[3],dir-90),y+lengthdir_y(left_arm_pos_x[3],dir-90)+left_arm_pos_y[3],z+left_arm_pos_z[3]);
d3d_model_draw(left_arm_model[3],0,0,0,left_arm_texture[3]);
d3d_transform_stack_pop();
Its tricky because the shoulder and hand's position is calculated from the objects coor and they both work fine in keeping their positions, but the elbow gets its coor from the hand and shoulder so its not set via a lengthdir radius from the objects position but it also has to do it to correct for the rotation

Using the variable elbow_difference was my attempt at getting it to work because I couldn't figure out how to draw the elbow model where it needed to be as it wasn't even visible on the screen

@TheouAegis
@flyingsaucerinvasion
 
Last edited:

FrostyCat

Redemption Seeker
Use hierarchical transformations instead of calculating each joint coordinate manually, then you won't have this issue.

See the first half of these lecture notes for an explanation of hierarchical transformations.
 

kupo15

Member
Use hierarchical transformations instead of calculating each joint coordinate manually, then you won't have this issue.

See the first half of these lecture notes for an explanation of hierarchical transformations.
Ok I'll check this out. Two things:

So I guess I should still be using models and not switch to regular drawing or does it not make a difference?
Secondly, this wouldn't really be applicable to a catching arm where you control the hand? So far it works pretty well in my 2d version of it.


I was planning on using stacks for the legs...maybe for the stick hand
Or would you still recommend replacing my glove hand with stacks?
 
Top