Notifications
Clear all

[Closed] Angle between point

Thanks for the reply
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

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

with redraw off
(
	disablerefmsgs()
	delete objects
	enablerefmsgs()

	sp = line name:#angle_shape wirecolor:yellow
	addnewspline sp
	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
	updatesplineshape sp

	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()
	s.addnode #self ar
	s.addnode #a pa
	s.addnode #c pc
	s.addnode #b pb
	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

Thanks Denis.

it’s usufull

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

x >> #spline_1___vertex_N

x = 3*N – 1

Page 2 / 2