fig. 6 I would suggest is equivalent to your first example where you have two fixed motors with one not firing.
I would suggest that the vector force would be divided up as shown in fig. 3

Neither did I.deltarho[1859] wrote:I cannot see what BasicCoder2's last post is adding more to the conversation than the second post did; or am I missing something?
badidea wrote:Neither did I.deltarho[1859] wrote:I cannot see what BasicCoder2's last post is adding more to the conversation than the second post did; or am I missing something?
As I don't see a real difference between the flying saucer and the borg cube, I expect both to move in y-direction only while rotating. (assuming the thruster fires shortly, like impulse). Working on some code now...
BasicCoder2 wrote:The borg cube is of course 3d and a lot more complicated.
BasicCoder2 wrote:Hitting a circle is the same at any point.
BasicCoder2 wrote:The angle you hit a square will depend on the orientation of the square.
dodicat wrote:Here is a general strike.
I have used the property of mass of a disc and moment of inertia of a disc.
...
Code: Select all
linearimpulse = impulse * Cos(a) / mass
angularimpulse = impulse * Sin(a) / anginertia
May be force are not with you if you don't understand :lol:dodicat wrote:(The laws of physics apply everywhere), maybe not here.
Code: Select all
...
' german: Winkelgeschwindigkeit
type tAngularVelocity as tReal ' = cross(d,F)
' german: Drehmoment
' Torque is a measure of how much a force acting on an object causes that object to rotate.
type tTorque as tVector ' = angular acceleration
...
Code: Select all
' pseudo cross product last row from 3D cross product !
operator \(l as tVector, r as tVector) as tReal
return l.x*r.y - l.y*r.x
end operator
badidea wrote:I expect both to move in y-direction only while rotating.
badidea wrote:dodicat wrote:Here is a general strike.
I have used the property of mass of a disc and moment of inertia of a disc.
...
Looking at you code, but I is a bit hard to follow. Not written for a beauty contest :-)Code: Select all
linearimpulse = impulse * Cos(a) / mass
angularimpulse = impulse * Sin(a) / anginertia
You assume that linear impulse is in cos(a) direction and angular impulse in sin(a) direction. But that is were a have my doubts, unless simulation pool billiard.
Code: Select all
Type pt
As Single x,y,z
End Type
Function length(p1 As pt) As Single
Return Sqr( (p1.x)^2 + (p1.y)^2+ (p1.z)^2)
End Function
Function unit(p1 As pt) As pt '=normalize
Dim As Single L=length(p1)
Return Type(p1.x/L,p1.y/L,p1.z/L)
End Function
#define dround(n,places) mid((str(int((n)*10^(places)+.5)/10^(places))),1,instr(ltrim(str((n)),"-"),".")+(places)+1)
#define onscreen (mx>0) and (mx<xres) and (my>0) and (my<yres)
#define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius
Const pi=4*Atn(1)
Function cross(v1 As pt,v2 As pt) As pt '|cross product|= |v1| * |v2| *sin(angle between v1 and v2)
Return Type(v1.y*v2.z-v2.y*v1.z,-(v1.x*v2.z-v2.x*v1.z),v1.x*v2.y-v2.x*v1.y)
End Function
Function getangle(p() As pt) As Single
Dim As pt L1=(p(1).x-p(2).x,p(1).y-p(2).y)'leg 1
Dim As pt L2=(p(3).x-p(2).x,p(3).y-p(2).y)'leg 2
Dim As Single angle=Asin(length(cross(unit(L1),unit(L2))))*(180/pi)'angle between legs in degrees
If cross(l1,l2).z>0 Then angle=360-angle
Return angle
End Function
#macro display
angle=getangle(p())
Screenlock
Cls
Color 15
Draw String (20,20), "Drag circles by leftmouse button"
Color 3
Draw String (20,40), "Angle from red to green line (clockwise) in degrees"
Color 15
For z As Long=1 To 3
Circle (p(z).x,p(z).y),5,7,,,,f
Next
Line(p(2).x,p(2).y)-(p(1).x,p(1).y),2
Line(p(2).x,p(2).y)-(p(3).x,p(3).y),4
Color 3
Draw String(p(2).x+20,p(2).y),Iif(Instr(dround(angle,2),"."),Rtrim(dround(angle,2),"0"),dround(angle,2))+chr(248)
Screenunlock
#endmacro
#macro mouse(m)
Dim As Long x=mx,y=my,dx,dy
While mb = 1
Display():Sleep 1,1
Getmouse mx,my,,mb
If onscreen Then
If mx<>x Or my<>y Then
dx = mx - x
dy = my - y
x = mx
y = my
p(m).x=x+dx
p(m).y=y+dy
End If
End If
Wend
#endmacro
Screen 19
Dim As Integer xres,yres
Screeninfo xres,yres
Dim As pt p(1 To 3)={(100,100),(300,200),(200,400)} 'arbitary starting points
Dim As Integer mx,my,mb
dim as single angle
Do
Getmouse(mx,my,,mb)
display:Sleep 1,1
For n As Long=1 To 3
If incircle(p(n).x,p(n).y,10,mx,my) And mb=1 Then
mouse(n)
End If
Next n
Loop Until Len(Inkey)
BasicCoder2 wrote:badidea wrote:I expect both to move in y-direction only while rotating.
You may be right with an object hitting a Borg ship. The boat and it's motor interacts with the water it is not skidding along a frictionless frozen lake with a rocket for propulsion.
https://www.youtube.com/watch?v=qaIqanZ00uo
However if there was a rocket engine on the block it would turn with the block and thus change the direction of the force in absolute space?
So to test this you would need to have a rocket of some kind (water bottle with vinegar and baking soda dissolved in water?) and a low friction setup such as a disc on an ice rink.
BasicCoder2 wrote:However if there was a rocket engine on the block it would turn with the block and thus change the direction of the force in absolute space?
So to test this you would need to have a rocket of some kind (water bottle with vinegar and baking soda dissolved in water?) and a low friction setup such as a disc on an ice rink.
dodicat wrote:I don't think you have a third thing in space.
dodicat wrote:On your own out there you could be stuck in the one place no matter how much you thrashed around.
Code: Select all
Const pi=4*Atn(1)
Const BoxSize=100
Const systemconstant=1/boxsize
#define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius
#define onscreen (mx>0) and (mx<xres) and (my>0) and (my<yres)
Type pt
As Double x,y,z
End Type
Redim Shared As pt msg()
Operator -(p1 As pt,p2 As pt) As pt
Return Type(p1.x-p2.x,p1.y-p2.y)
End Operator
Operator +(p1 As pt,p2 As pt) As pt
Return Type(p1.x+p2.x,p1.y+p2.y)
End Operator
Operator *(f As Single,p As pt) As pt
Return Type(f*p.x,f*p.y)
End Operator
Function length(p1 As pt,p2 As pt) As Single
Dim As Single diffx=p1.x-p2.x,diffy=p1.y-p2.y
Return Sqr(diffx*diffx+diffy*diffy)
End Function
Function unit(p1 As pt) As pt
#define lngth(p) Sqr( (p1.x)^2 + (p1.y)^2+ (p1.z)^2)
Dim As Single L=lngth(p1)
Return Type(p1.x/L,p1.y/L,p1.z/L)
End Function
Function dot(v1 As pt,v2 As pt) As Single 'dot product |v1| * |v2| *cos(angle between v1 and v2)
Return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
End Function
Function cross(v1 As pt,v2 As pt) As pt '|cross product|= |v1| * |v2| *sin(angle between v1 and v2)
Return Type(v1.y*v2.z-v2.y*v1.z,-(v1.x*v2.z-v2.x*v1.z),v1.x*v2.y-v2.x*v1.y)
End Function
Function getangle(p() As pt) As Single
Dim As pt L1=(p(1).x-p(2).x,p(1).y-p(2).y)'leg 1
Dim As pt L2=(p(3).x-p(2).x,p(3).y-p(2).y)'leg 2
Dim As Single angle=Acos(dot(unit(L1),unit(L2)))*(180/pi)'angle between legs in degrees
If cross(l1,l2).z>0 Then angle=360-angle
Return angle
End Function
'=========================
Function inpolygon(p1() As Pt,Byval p2 As Pt) As Long
#macro Winder(L1,L2,p)
((L1.x-L2.x)*(p.y-L2.y)-(p.x-L2.x)*(L1.y-L2.y))
#endmacro
Dim As Integer index,nextindex,k=Ubound(p1)+1,wn
For n As Integer=1 To Ubound(p1)
index=n Mod k:nextindex=(n+1) Mod k
If nextindex=0 Then nextindex=1
If p1(index).y<=p2.y Then
If p1(nextindex).y>p2.y Andalso Winder(p1(index),p1(nextindex),p2)>0 Then wn+=1
Else
If p1(nextindex).y<=p2.y Andalso Winder(p1(index),p1(nextindex),p2)<0 Then wn-=1
End If
Next n
Return wn
End Function
Sub drawpolygon(b() As pt,p() As Pt,rotmsg() As pt,Byref col As Ulong,Byval im As Any Pointer=0)
Dim k As Long=Ubound(p)+1
Dim As Long index,nextindex
Dim As Long cx,cy
For n As Long=1 To Ubound(p)
cx+=p(n).x:cy+=p(n).y
index=n Mod k:nextindex=(n+1) Mod k
If nextindex=0 Then nextindex=1
Line im,(p(index).x,p(index).y)-(p(nextindex).x,p(nextindex).y),col
Next
cx/=Ubound(p):cy/=Ubound(p)
Paint (cx,cy),col,col
For n As Long=Lbound(rotmsg) To Ubound(rotmsg)
Pset(rotmsg(n).x,rotmsg(n).y),rotmsg(n).z'rgb(200,0,0)
Next n
End Sub
Function rotate(pivot As pt,p As pt,a As Single,d As Single=1) As pt
Return Type<pt>(d*(Cos(a)*(p.x-pivot.x)-Sin(a)*(p.y-pivot.y)) +pivot.x,_
d*(Sin(a)*(p.x-pivot.x)+Cos(a)*(p.y-pivot.y)) +pivot.y)
End Function
Sub setUpPolygon(b() As pt,sz As Long,x As Long,y As Long,num As Long)
Redim b(1 To num)
Dim As Long ctr
For n As Single=0 To 3*pi Step 2*pi/num
ctr+=1
If ctr>num Then Exit For
b(ctr).x=x+sz*Cos(n)
b(ctr).y=y+sz*Sin(n)
Next n
End Sub
Sub turnpolygon(b() As pt,rot() As pt,rotmsg() As pt,a As Single,f As pt,translate As pt)
For n As Long=Lbound(rot) To Ubound(rot)
rot(n)= rotate(f,b(n),a)
rot(n)+=translate
Next n
For n As Long=Lbound(rotmsg) To Ubound(rotmsg)
rotmsg(n)= rotate(f,msg(n),a)
rotmsg(n)+=translate
rotmsg(n).z=msg(n).z
Next n
End Sub
Function movepolygon(b() As pt,msg() As pt,dirn As pt) As pt
Dim As pt p
For n As Long=Lbound(b) To Ubound(b)
b(n).x+=dirn.x
b(n).y+=dirn.y
p.x+=b(n).x
p.y+=b(n).y 'get centre
Next
For n As Long=Lbound(msg) To Ubound(msg)'move message
msg(n).x+=dirn.x
msg(n).y+=dirn.y
Next
Dim As Long size=Ubound(b)-Lbound(b)+1
Return Type(p.x/size,p.y/size)
End Function
Function shortline(fp As pt,p As pt,Ln As Long) As pt 'line of ln length
Dim As Single diffx=p.x-fp.x,diffy=p.y-fp.y
Dim As Single L=Sqr(diffx*diffx+diffy*diffy)
Return Type(fp.x+Ln*diffx/L,fp.y+Ln*diffy/L)
End Function
Function drawline(x As Long,y As Long,angle As Single,dist As Long) As pt'line by angle
Var x2=x+dist*Cos(angle)
Var y2=y+dist*Sin(angle)
Return Type(x2,y2)
End Function
'all the lines
Function lineto(c As pt,_out As pt,p2() As pt,dirn As pt,Byref strike As Long,b() As pt) As Single
Var L=length(p2(1),p2(2))
Var ang=Atan2(p2(2).y-p2(1).y,p2(2).x-p2(1).x)
Dim As pt p=p2(1)
Dim As Long ic,ctr
Do
p=shortline(p,p2(2),1)
ic=inpolygon(b(),p)
ctr+=1
If ic Then strike=1 Else strike=0
Loop Until ic Or ctr>L 'when it hits the box at p
Line(p.x,p.y)-(p2(1).x,p2(1).y),Rgb(0,200,0) 'surface to the red point
If strike Then Line(c.x,c.y)-(p.x,p.y)
Dim As pt eq=drawline(c.x,c.y,ang,-200)
Dim As pt q=Type(c.x,c.y)
ctr=0
Do
q=shortline(q,eq,1)
ic=inpolygon(b(),q)
ctr+=1
Loop Until ic=0 Or ctr>400 'when exits the box at q
If strike Then Line(c.x,c.y)-(q.x,q.y)
Dim As pt pp(1 To 3)={c+(c-q),c,c+(c-p)} 'array to hold three points (two legs metting at t)
_out=p 'out the intersection wth box
dirn=unit(p-c) 'out the direction
Dim As pt d=.3333*(p+q+c)'to show the angle
Dim As Single angle=getangle(pp())
If strike Then Draw String(d.x,d.y),Str(Int(angle))
Return angle*pi/180 'return in radians
End Function
Function Regulate(Byval MyFps As Long,Byref fps As Long=0) As Long
Static As Double timervalue,_lastsleeptime,t3,frames
Var t=Timer
frames+=1
If (t-t3)>=1 Then t3=t:fps=frames:frames=0
Var sleeptime=_lastsleeptime+((1/myfps)-T+timervalue)*1000
If sleeptime<1 Then sleeptime=1
_lastsleeptime=sleeptime
timervalue=T
Return sleeptime
End Function
Sub HandleRain(rain As Any Ptr)
Var max=100
Static As Single xx(max),yy(max)
For i As Long = 0 To max
xx(i) = Rnd*1024
yy(i) = Rnd*768
Put(xx(i),yy(i)),Rain,Alpha,200+Rnd*50
Next
End Sub
#macro display
flag2=0
Screenlock
Cls
Draw String(20,20),"Move the small circles by mouse"
Draw String(20,50),"Press spacebar for impulse"
Draw String(20,80),"Right mouse click to reset"
Draw String(20,110),"Angular speed " &abs(angularimpulse*180/pi)
Draw String(20,140),"Linear speed " &speed
Draw String(20,170),"framerate = " &fps,Rgb(0,200,0)
pivot=movepolygon(b(),msg(),Type(dx,dy))
turnpolygon(b(),rot(),rotmsg(),-turn,pivot,Type(dx,dy))
drawpolygon(b(),rot(),rotmsg(),Rgb(0,100,255))'draw the polygon and return the centre
c=Type<pt>(xres\2,yres\2) 'centre
If flag=0 Then
Locate 15
Print " weight "; impulse
flag2=1
a= lineto(c,_out,p2(),dirn,strike,rot()) 'a=angle return as shown in radians
End If
If Len(Inkey) And flag2 And strike Then
flag=1
linearimpulse=impulse*Cos(a)/mass
If a>pi/2 And a<3*pi/2 Then dirn=-1*dirn
dx=-dirn.x*linearimpulse
dy=-dirn.y*linearimpulse
angularimpulse=impulse*Sin(a)/anginertia
speed=Sqr(dx*dx+dy*dy) 'to show value on screen
End If
For z As Long=1 To 2 'the two drag spots
Dim As Ulong clr=Iif(z=1,Rgb(200,0,0),Rgb(0,200,0))
Circle (p2(z).x,p2(z).y),5,clr,,,,f
Next
If flag=0 Then impulse=length(p2(1),_out) 'arbitrary weight as a function of mouse potition
turn+=angularimpulse
handlerain(rain)
Screenunlock
Sleep regulate(60,fps),1
'====================
#endmacro
#macro mouse(m)
Scope
Dim As Long x=mx,y=my,dx2,dy2
While btn = 1 Or btn=2
Display
Getmouse mx,my,,btn
If onscreen Then
If mx<>x Or my<>y Then
dx2 = mx - x
dy2 = my - y
x = mx
y = my
p2(m).x=x+dx2
p2(m).y=y+dy2
End If
End If
Wend
End Scope
#endmacro
Sub MakeMsg(msg() As pt,xres As Long,yres As Long)
Cls
Redim msg(0)
Print " Gone"+Chr(10)+"Fishing"
Dim As Long ctr
Var c=Point(1,1)
For x As Long=0 To 60
For y As Long=0 To 45
If Point(x,y)<>c Then
ctr+=1
Redim Preserve msg(1 To Ubound(msg)+1)
msg(Ubound(msg))=Type(x+xres/2,y+yres/2,Rgb(.75*ctr,255-.75*ctr,ctr/6))
End If
Next
Next
End Sub
Function pickanumber As Long
Cls
Locate 12
Print "click a number"
#define map(a,b,_x_,c,d) ((d)-(c))*((_x_)-(a))/((b)-(a))+(c)
Dim As Long mx,my,mb,ret
Do
Getmouse mx,my,,mb
Locate 15
If my>220 And my<235 Then
Color ,Rgb(100,0,0)
var n=Int(map(5,655,mx,3,30))
If mx<675 Then Print Tab(90);"Choose ";n;" ?"
If mb Then ret=map(0,660,mx,3,30)
Else
Color ,Rgb(0,0,0)
End If
Locate 15
For n As Long=3 To 30
Print Right("0"+Str(n),2)+" ";
Next
Print
sleep 10
Loop Until ret
Color ,Rgb(0,0,0)
Return ret
End Function
Screen 20,32
Dim As Integer xres,yres
Screeninfo xres,yres
Dim As Single dx,dy,a,turn,angularimpulse,impulse,linearimpulse,speed
Dim As Single mass
Dim As Single anginertia
Dim As Long mx,my,btn,flag,flag2,fps,strike
Dim As pt c
Dim As pt _out,p2(1 To 2)={(200,200),(650,500)},dirn
Redim As pt b()
Dim As Long numsides
start:
numsides=pickanumber
'area of a regular polygon
mass= systemconstant*boxsize^2*numsides*sin(2*pi/numsides)/2
'moment of inertia of a regular polygon
anginertia=systemconstant*((mass*boxsize^2)/6)*(1+2*(Cos(pi/numsides)^2))
MakeMsg(msg(),xres-40,yres-40)'create a string message
setUpPolygon(b(),boxsize*Sqr(2),xres\2,yres\2,numsides)
Redim As pt rot(Lbound(b) To Ubound(b)) 'to hold rotated shape
Redim As pt rotmsg(Lbound(msg) To Ubound(msg))''to hold rotated message
Dim As pt pivot
Dim As Any Ptr Rain=Imagecreate(5,20)
Line rain,(0,0)-(5,20),Rgb(50,50,55)
Do
Getmouse mx,my,,btn
strike=0
display
For n As Long=1 To 2
If incircle(p2(n).x,p2(n).y,10,mx,my) And btn=1 And flag2=1 Then
mouse(n)
End If
Next n
If btn=2 Or pivot.x<BoxSize Or pivot.x>xres-BoxSize Or pivot.y<BoxSize Or pivot.y>yres-BoxSize Then 'reset
Screenunlock
sleep 1
dx=0
dy=0
a=0:flag=0
angularimpulse=0
speed=0
turn=0
Goto start
End If
Loop Until Multikey(1)
Imagedestroy rain
Sleep
Users browsing this forum: No registered users and 0 guests