[Closed] Angle between point
Dear all:
I’m trying to make a script to animate the position of the points so that a shape = ARC can form the arc. These must be controlled, in such a way that when moving the Points in any direction, the Arc can also form the arc of the angle. I place an image to explain myself better.
If you have any script proposed, I would appreciate if you write me. Thank you very much (richardvillagaray@gmail.com)
Dear all:
What I would like is that when moving any of the points, the arc, automatically regulates its angle … I know that CONTROLLERS must be placed for that.
Please helpe me !
create objs , point001 、point002 、point003、 Arc001 、Text001 、Line001 with 3 corner knots、dummy001
set point002 、 Arc001 to [0,0,0], set point003 to [10,0,0]
add lookat constraint to Arc001 , target point003
set Arc001 as child of point002
change dummy001’s scale controller to scale script
add variables to scale script controller , a、b、c、arc、txt、bound
assige the variables to the objs one by one , no dummy
change the script to below
aa = (atan2 (a.pos[2] - b.pos[2]) (a.pos[1] - b.pos[1])) - (atan2 (c.pos[2] - b.pos[2]) (c.pos[1] - b.pos[1]))
if aa < 0 do aa += 360
arc.tO=aa
txt.text = aa as string
setKnotPoint bound 1 1 a.pos
setKnotPoint bound 1 2 b.pos
setKnotPoint bound 1 3 c.pos
updateshape bound
mm=(arc.transform.rotation as eulerAngles).z_rotation + (arc.to/2)
txt.pos= [cos(mm),sin(mm),0] * 15 + b.pos
[1, 1, 1]
see the result
Dear AEI:
Where can I get more training for CONTROLLERS??? especially the spline. To make animations with Maxscript
Thank you
I didn’t know is there a book or website for this in English world , no one in my country , most time we need explore by ourselves , only sporadic tutorial in some video site
maybe official help is the best choice
OK, thanks.
I did
(
p0= Point name:“P0” wirecolor:green pos:[45,45,0]
p1= Point name:“P1” wirecolor:green pos:[100,150,0]
p2= Point name:“P2” wirecolor:green pos:[-100,150,0]
Obj = Arc name:“TheAngle” radius:25 from:0 wirecolor:yellow render_renderable:true
–$TheAngle.to = acos(dot (normalize(V1-V0)) (normalize(V2-V0)))
posCtrl = Position_Constraint()
$TheAngle.pos.controller = posCtrl
posConstraintInterface = posCtrl.constraints
posConstraintInterface.appendTarget $P0 100
posConstraintInterface.setWeight 1 100
Lc = LookAt_Constraint()
$TheAngle.rotation.controller = Lc
locConstraint = Lc.constraints
locConstraint.appendtarget $P1 100
Lc.lookat_vector_length = 30
Ctrl_Angle = float_script ()
$TheAngle.to.controller = Ctrl_Angle
Txt=“V0=$P0.transform.controller.Position;\n”
Txt+=“V1=$P1.transform.controller.Position;\n”
Txt+=“V2=$P2.transform.controller.Position;\n”
Txt+=”$TheAngle.from=0;\n”
Txt+=”$TheAngle.to=acos(dot (normalize(V1-V0)) (normalize(V2-V0)))\n”
Ctrl_Angle.script=Txt
)
$ method should be avoided , when you multi merge , $ method won’t update itself
Is there any way for this issue which works at any situaton ?
for example your code is fine But it doesn’t work when both object are not at the same position
here we go
–Create our scene
MAin_pt = Point wirecolor:green size:160 Box:off axistripod:off centermarker:off cross:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [150,0,150])
Obj_Center= circle radius:60 wirecolor:Red transform:MAin_pt.transform
objA= point wirecolor:Red Box:off axistripod:off centermarker:off cross:on
objA.position.controller = position_list()
pa_Con= Path_Constraint () ; objA.position.controller = pa_Con ; pa_Con.path = Obj_Center
objB = point wirecolor:yellow pos:objA.pos Box:on axistripod:off centermarker:off cross:off parent:MAin_pt
showangle = Cylinder transform:Obj_Center.transform heightsegs:1 capsegs:1 sides:18 height:1 radius:6 slice:on parent:MAin_pt wirecolor:red; showangle.sliceFrom = 0.01
Scl_Pt = point()
Scl = Scl_Pt.scale.controller = scale_script()
scl.addnode "Obj_Center" Obj_Center
scl.addnode "objA" objA
scl.addnode "objB" objB
scl.addnode "Th_Cyl" showangle
scl.script =
"
DD = (atan2 (objA.pos[2] - Obj_Center.pos[2]) (objA.pos[1] - Obj_Center.pos[1])) - (atan2 (objB.pos[2] - Obj_Center.pos[2]) (objB.pos[1] - Obj_Center.pos[1]))
The_angle = (acos (dot (normalize ( objA.pos - Obj_Center.pos )) (normalize ( objB.pos - Obj_Center.pos ))))
if DD<0 then Th_Cyl.sliceFrom = The_angle + .001
else Th_Cyl.sliceFrom = (360 - The_angle) + .001
print DD
[1, 1, 1]
"
It works fine evenwe move all objects to anothe position it works fine
BUT!!
If we move second object to difrent position than Object1
objB.pos = [195,0,110]
It doesn’t work fine!!!
what you are using is XY axis code, but you use it in XZ axis , that’s why you can’t get the result , not only B , A wrong too
you need modifier the code to XZ axis , or you need a local axis code , for that , a grid is needed for the normal , otherwise only acute angle is correct .