[Solved]Weld two circle shapes to one anothers edge with conditions

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

[Solved]Weld two circle shapes to one anothers edge with conditions

Post by ArchAngel075 »

Problem :
We have two circle bodies c1 and c2 of radius r1 and r2 (love.physics made)
we place these circles such that r1 is above r2 and they are in contact with no overlap.

I wish to loosely weld c1 to c2 such that c2 always is attached to the point it is in contact with from creation.
Or specifically, assume p1 is the point r1 distance from c1 towards c2;
IF c1 rotates, c2 will move as if it is attached to the point p1, BUT I want this attachment to be springy aswell,
That is I wish for c2 to be able to move asif attached by a spring to point p1.
Lastly the circles will shrink or grow constantly based on outside influences

Solution I Use : (not working)
Let the two circles be named A and B respectively

Create two bodies of size s ( s = 6 ) :
p1 is placed r1 distance away from c1 at angle towards c2
p2 is placed r2 distance away from c2 at angle towards c1
--Essentially now both points are next to one another too.
--These points are welded at their position on their respective circles and will never collide with anything, ie:

Code: Select all

p1_weld = love.physics.newWeldJoint(p1,c1,p1.position.x,p1.position.y,false)
p2_weld = love.physics.newWeldJoint(p2,c2,p2.position.x,p2.position.y,false)
Now p1 and p2 will be distance joined to each other :

Code: Select all

distanceJoint = love.physics.newDistanceJoint(p1,p2,0,0,0,0,false)
This should allow the circles c1 and c2 to rotate and move while influencing p1 and p2 the edge respectively, WHILE being distance joined.

To ensure the points are always on the edge of their circle we use setPosition every love.update() :

Code: Select all

angle = the angle c1 to p1
r = the radius of c1

p1x = math.cos(angle)*r
p1y = math.sin(angle)*r

p1:setPosition(p1x,p1y)
--
angle = the angle c2 to p2
r = the radius of c2

p2x = math.cos(angle)*r
p2y = math.sin(angle)*r

p2:setPosition(p2x,p2y)

Notes
In theory this works, yet i experience constantly weird results.
I need the circles to be free to pull apart and grow/shrink and since I can not move anchor points of any joint its impossible to make a single Distance joint between c1 and c2 at the edges and then update the anchors to respective radii on growth and shrinkage.
I have to use separate bodies that i can move which would move the anchors (my theory)

Does anyone have any idea how i can solve my above problem ?
Last edited by ArchAngel075 on Wed Mar 29, 2017 8:20 pm, edited 1 time in total.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Weld two circle shapes to one anothers edge with conditions

Post by airstruck »

I'm not getting why you need two weld joints (in the same place?) and also a distance joint (also in the same place?). It seems like a single weld joint would do it, I must be missing something.

Anyway, since you can't move a joint's anchor points once it's created, it looks like the most obvious solution is to trash the joint and create a new one whenever its anchor point position needs to change in relation to a connected body.

Your idea about creating another body just for anchoring the joint could work, but I'm not sure how you'll get it to stick to the edge of the circle without running into the same issue. Maybe something like a prismatic joint with motor enabled pushing it towards the circle?
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Weld two circle shapes to one anothers edge with conditions

Post by ArchAngel075 »

airstruck wrote: Tue Mar 28, 2017 12:59 pm I'm not getting why you need two weld joints (in the same place?) and also a distance joint (also in the same place?). It seems like a single weld joint would do it, I must be missing something.

Anyway, since you can't move a joint's anchor points once it's created, it looks like the most obvious solution is to trash the joint and create a new one whenever its anchor point position needs to change in relation to a connected body.

Your idea about creating another body just for anchoring the joint could work, but I'm not sure how you'll get it to stick to the edge of the circle without running into the same issue. Maybe something like a prismatic joint with motor enabled pushing it towards the circle?
You are correct, rethinking it using one weld joint is still viable

The trashing and recreation of the joint will not work correctly, the joint will be recreated every love.update() call as the circles are resizing constantly (constant loss or growth, either constantly using dt or small/large jumps of size under conditions)
I recall trying a recreated joint every update and it resulted in weird results where circles are bound together as one system but rotations and such imposed are loss. Ie i can spin one circle and the joint does not cause pull or push effects

_

Though u have found a solution that involved making one distance joint, it never gets changed after creation and resizing the circles does not result in any issues (unless wither is shrunken enough, but other logic will prevent that from ever occurring)
Though id prefer a more consistent solution.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Weld two circle shapes to one anothers edge with conditions

Post by airstruck »

Do circles only come in pairs, or can more than two be stuck together? If each circle is only connected to one other circle, you should be able to put the edge of the circle shape at the body's origin, so the joint won't need to change position in relation to the body.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Weld two circle shapes to one anothers edge with conditions

Post by ArchAngel075 »

Circles will be in many clumps or alone.
Its various 'cells of a organism' or 'single cell organisms'
I do hope to have a demo of what im working on soon.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Weld two circle shapes to one anothers edge with conditions

Post by airstruck »

Oh well, so much for that idea.
I do hope to have a demo of what im working on soon.
Nice, I'm interested in seeing how you solved it.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Weld two circle shapes to one anothers edge with conditions

Post by ArchAngel075 »

Solution worked using the prismatic joint...somewhat

I have two physics bodies with essentially the same properties (other than size)
If i create the joint on body type A then it works(sorta, there is a weird overlap but its actually nice looking... so feature not a bug)
If i create the joint on body type B then it breaks. The rotation of the first body (joined to B) causes Weird results.
I could record a short video to demonstrate the result if that would help.

Though I admit im abit lost how the prismatic join works, especially with Upper/Lower limit, i cant determine if the values are 0 <-> 1 or dx = distance between anchors.
Infact the anchors themselves also cause me some confusion, ive resulted in making the anchors x1,y1 | x2,y2 either the centers of the two bodies or the edges of the circles towards one another (or r1 towards p2 | r2 towards p1)
Im using anchor method 2 at the moment.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Weld two circle shapes to one anothers edge with conditions

Post by airstruck »

Try this thing out, it's good for experimenting with stuff like that.

https://github.com/airstruck/lps

Don't remember the details on prismatic off hand, will have a look when I get a chance.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Weld two circle shapes to one anothers edge with conditions

Post by ArchAngel075 »

Righto, i have a result I am really happy with, it satisfies all but one of my requirements and the unsatisfied requirement is more a cosmetic desire, the joints lock and keep distance correctly and the joint acts correctly regardless of what I connect it to. The unsatisfied requirement is that the joints are not springy, that is the bodies A and B have no ability to separate with elasticity as if connected by a spring, this is fine - ill take what I have.

Ill admit some foolish mistake, somewhere in the process of testing i locked the rotation of body type 1 which is why there as inconsistent results....oops.

I set the anchors to the two bodies centers each, I now apply rotation using angularVelocity not setAngle (since in my experience set(Angle/Position) causes weird forceful collision results.
I also set the Lower and Upper to -1 and 1 respectively which results in zero leeway.

Maybe now I can move onto the bulky cell division feature (little peak at what working on, which should demand a video after cell division is implemented)
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: [Solved]Weld two circle shapes to one anothers edge with conditions

Post by airstruck »

ArchAngel075 wrote:The unsatisfied requirement is that the joints are not springy, that is the bodies A and B have no ability to separate with elasticity as if connected by a spring
When I mentioned prismatic joints, I was actually thinking of your suggestion about having additional "connector bodies" for anchoring weld joints to. Instead of joining two cells together with a prismatic, I'm thinking for each connection, you join a small connector body to the cell with a prismatic, and then you join the two connector bodies together with a loose weld. Maybe that's overkill, though.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 65 guests