Page 1 of 1
How to set a rectangular workspace on a conveyer belt
Posted: 02 Apr 2020, 23:24
by alix
Hi.
My question can be bit confusing, but please bear with me. I want to define a rectangular space on a conveyer belt. So the robot will try to reach target being within that rectangle. Not outside that rectangle. How can i define that rectangle in vrep through my code? Is there any way that the target automatically gets randomly positioned at any coordinates within that rectangle?
Thanks.
Regards,
Re: How to set a rectangular workspace on a conveyer belt
Posted: 03 Apr 2020, 09:53
by fferri
Not sure I understand what you mean.
You can define a quadrilateral with 4 dummies, and sample a point inside it using math.random
.
Re: How to set a rectangular workspace on a conveyer belt
Posted: 03 Apr 2020, 13:24
by alix
fferri wrote: ↑03 Apr 2020, 09:53
Not sure I understand what you mean.
You can define a quadrilateral with 4 dummies, and sample a point inside it using
math.random
.
Hi fferi,
Thanks for the reply. This is exactly what i am trying to do. Can you please elaborate a bit about how to define the quadrilateral and sample point?
Thanks again
Re: How to set a rectangular workspace on a conveyer belt
Posted: 03 Apr 2020, 13:35
by fferri
Let \(\alpha,\beta\) two real numbers uniformly sampled from \([0,1]\) you can define your point as \(p=(1-\beta) ((1-\alpha) A + \alpha D) + \beta ((1-\alpha) B + \alpha C)\)
In Lua code:
Code: Select all
function interp(a,b,t)
local r={}
for i=1,#a do r[i]=(1-t)*a[i]+t*b[i] end
return r
end
local alpha=math.random()
local beta=math.random()
local p=interp(interp(A,D,alpha),interp(B,C,alpha),beta)
Re: How to set a rectangular workspace on a conveyer belt
Posted: 03 Apr 2020, 23:11
by alix
fferri wrote: ↑03 Apr 2020, 13:35
Let \(\alpha,\beta\) two real numbers uniformly sampled from \([0,1]\) you can define your point as \(p=(1-\beta) ((1-\alpha) A + \alpha D) + \beta ((1-\alpha) B + \alpha C)\)
In Lua code:
Code: Select all
function interp(a,b,t)
local r={}
for i=1,#a do r[i]=(1-t)*a[i]+t*b[i] end
return r
end
local alpha=math.random()
local beta=math.random()
local p=interp(interp(A,D,alpha),interp(B,C,alpha),beta)
Thankyou So much for your detailed help fferi... I'll try it now.
Thanks again