# Angle between point

#1

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)

#2

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.

#3

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
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

#4

Ok thanks, I’m going to check it out and test it.

#5

Dear AEI:

Where can I get more training for CONTROLLERS??? especially the spline. To make animations with Maxscript

Thank you

#6

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

#7

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

)

#8

\$ method should be avoided , when you multi merge , \$ method won’t update itself

#9

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])
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.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!!!

#10

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 .

#11

I tried what you’ve said, But I think the problem still does exist !!
At the start
when both ObjA & ObjB are at the same position script works fine.
But when you move not moving one ( ObjB here in the example ) and move another one objA there will be problem! vise versa.
-----------------------------------EDIT
If obA is at its initial postion and you move ObjB it works, But if you objA from its initial position and then Move objB theere will be problem

#12

I gave the right way to get the angle , you’d like to use what yourselves’ , then you should fix it to right

#13
``````with redraw off
(
disablerefmsgs()
delete objects
enablerefmsgs()

sp = line name:#angle_shape wirecolor:yellow
sp.vertexticks = on

pa = point name:#point_A size:15 parent:sp pos:[0,0,50] wirecolor:green
pc = point name:#point_C size:20 parent:sp pos:[0,0, 0] wirecolor:orange
pb = point name:#point_B size:15 parent:sp pos:[50,0,0] wirecolor:green

pa.pos.controller = linear_position()
pc.pos.controller = linear_position()
pb.pos.controller = linear_position()

addknot sp 1 #corner #line pa.pos
addknot sp 1 #corner #line pc.pos
addknot sp 1 #corner #line pb.pos

animatevertex sp #all

master_c = sp.baseobject[#master].controller

/* cub indexs:
2 >> #spline_1___vertex_1
5 >> #spline_1___vertex_2
8 >> #spline_1___vertex_3
*/

paramwire.connect pa.transform.controller[#position] master_c[2] "position"
paramwire.connect pc.transform.controller[#position] master_c[5] "position"
paramwire.connect pb.transform.controller[#position] master_c[8] "position"

fn getMatrix a c b =
(
front = normalize (c - a)
side = normalize (c - b)
up = normalize (cross front side)
side = normalize (cross up front)
matrix3 front side up c
)

fn getAngle a c b =
(
v1 = normalize (c - a)
v2 = normalize (c - b)

ang = acos (dot v1 v2)
axs = (cross v1 v2)

angleaxis ang axs
)
--ang = getAngle pa.pos pc.pos pb.pos

ar = arc name:#arc pos:pc.pos from:180 wirecolor:red parent:sp
ax = point name:#axis size:10 axistripod:on box:on cross:off parent:ar pos:ar.pos wirecolor:red

s = ar.to.controller = float_script()
ss = "ang = getAngle pa.pos pc.pos pb.pos\n"
ss += "tm = getMatrix pa.pos pc.pos pb.pos\n"
ss += "self.transform = tm\n"
ss += "self.from + ang.angle"
s.setexpression ss

sp
)
``````

all math and mechanics are here.
but it’s a durty code from MXS point of view.
all functions must be local or moved in to a struct. or whole their body should be moved to the script controller(s)
the arc object #transform controller needs its own script insdeat of using arc’s #to controller script

#14

Thanks Denis.

it’s usufull

#15

Thanks Denist.

One question,
How do I calculate the numbers?

``````/* cub indexs:
2 >> #spline_1___vertex_1
5 >> #spline_1___vertex_2
8 >> #spline_1___vertex_3
*/``````

#16

x >> #spline_1___vertex_N

x = 3*N - 1