interpCurve3D - find angle of point in world coordsys- How?

Hello
I try to find angle of point on shape, use interpCurve3D. How can help me - how to do it?

Thank You

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Maarten's picture

Here is a way to do it

This code will find the angle of a given point for the selected spline obj. At the top of the code you can input which point in the spline you'd like to calculate the angle for, if no point is specified all points in the spline will be calculated. Make sure to select a spline before running the script. I used the cosine rule to get the angle.
Hope this helps,

-Maarten

-------------------------------------------------------------------------------------------------------
	--Set spline point equal to what point's angle you would like to get back from the script (printed)
	spline_point = undefined 
		--if spline_point is left undefined all angle values for the spline will be printed, which point in the spline each angles corresponds to will also be printed
-------------------------------------------------------------------------------------------------------
 
 
 
--declaring initial variables
knot_positions  = #()
knot_coords_x = #() ; knot_coords_y = #() ; knot_coords_z = #() ; Side_Lengths_A_arr = #() ; Side_Lengths_B_arr = #() ; Side_Lengths_C_arr = #() ; side_length ; Angles_arr =#()
index_1 ; index_2 ; index_3  
spl = selection[1]
vert_count = 6
j = 0
 
for s=1 to (numsplines spl) do( -- for each spline in the scene do
	--vert_count = (numknots spl s)
	for k = 1 to (numknots spl s) do ( --for each knot (each non open point in a spline) do
		format "spline_%_knot_%_pos = % \n" s k (getknotpoint spl s k)
		append knot_positions (getknotpoint spl s k) --append knot position [x,y,z]
 
		append knot_coords_x ( knot_positions[k][1] ) --append x-coordinate
		append knot_coords_y ( knot_positions[k][2] ) --append y-coordinate
		append knot_coords_z ( knot_positions[k][3] ) --append z-coordinate
 
	)
 
format "x coords = % \n y coords =% \n z coords =%  \n" knot_coords_x knot_coords_y knot_coords_z
 
 
for k=1 to (numknots spl s) do( --for each knot (each non open point in a spline) do
	--set initial index values (index_1 is used to get length A value for each triangle)
								--index_2 for length B
								--index_3 for length C
 
	index_1 = k ; index_2 = 1+k ; index_3 = 2+k
 
	--make sure the index values don't become equal to zero or go under zero (this would result in a "no 'get' function for undefined" undefined error
			if( (index_1) > (numknots spl s) )do(
				while index_1 > (numknots spl s) do (
					index_1 = index_1 - (numknots spl s)
					) 
				print "index_1 = index_1 - (numknots spl s)"
				)
 
			if( (index_2) > ( numknots spl s) )do(
				while index_2 > (numknots spl s) do (
					index_2 = index_2 - (numknots spl s)
					)  
				print "index_2 = index_2 - (numknots spl s) "
				)
 
			if( (index_3) > ( numknots spl s) )do(
				while index_3 > (numknots spl s) do (
					index_3 = index_3 - (numknots spl s)
					) 
				print "index_3 = index_3 - (numknots spl s) "
				)
 
			--Calculate triangle side lengths + Append triangle side lengths to corresponding array :
			Side_Length_A = sqrt (   (abs( -1*knot_coords_x[index_1] + knot_coords_x[index_2] ))^2 + (abs ( -1*knot_coords_y[index_1] + knot_coords_y[index_2] ))^2   ) 
				append Side_Lengths_A_arr Side_Length_A
				print side_length_A
 
			Side_Length_B = sqrt (   ( abs( -1*knot_coords_x[index_2] + knot_coords_x[index_3] ))^2 + (abs ( -1*knot_coords_y[index_2] + knot_coords_y[index_3] ))^2   ) 
				append Side_Lengths_B_arr Side_Length_B
				print Side_length_B	
 
			Side_Length_C = sqrt (   ( abs( -1*knot_coords_x[index_3] + knot_coords_x[index_1] ))^2 + (abs ( -1*knot_coords_y[index_3] + knot_coords_y[index_1] ))^2   ) 
				append Side_Lengths_C_arr Side_Length_C
				print Side_Length_C
 
	)
 
for k=(numknots spl s) to ((numknots spl s)*2-1) do( --starting at last knot in spline.. go through all points in the spline and do:
	index_1 = k ; index_2 = 1+k ; index_3 = 2+k
 
			if( (index_1) > (numknots spl s) )do(
				while index_1 > (numknots spl s) do (
					index_1 = index_1 - (numknots spl s)
					) 
				print "index_1 = index_1 - (numknots spl s)"
				)
 
	--k starts at last knot, first calculates length of A then B then C, need to calc. the B angle and append to Angles array 
	--Side_Lengths_A_Arr[index_1] = A
	--				 ..._B_Arr[index_1] = B
	--				 ..._C_Arr[index_1] = C
 
--use cosine rule to calculate angle B (angle B is the angle opposite to side C of each triangle)
	Angle_B = acos (  ( side_lengths_A_arr[index_1]^2 + side_lengths_B_arr[index_1]^2 - side_lengths_C_arr[index_1]^2 )/ (2* side_lengths_A_arr[index_1] * side_lengths_B_arr[index_1]) )
	/*print "Angle_B = acos (  ((side_lengths_A_arr[index_1])^2 + (side_lengths_C_arr[index_1])^2 - (side_lengths_B_arr[index_1])^2 )/ (2* side_lengths_A_arr[index_1] * side_lengths_C_arr[index_1]) ) \n"
	format "									A = %                                                        C = %                                             B = %                                          A = %                                 C = % \n\n" side_lengths_A_arr[index_1] side_lengths_C_arr[index_1] side_lengths_B_arr[index_1] side_lengths_A_arr[index_1] side_lengths_C_arr[index_1] 
	print ("side length A = ") ; print side_lengths_A_arr[index_1]
	print ("side length B = ") ; print side_lengths_B_arr[index_1]
	print ("side length C = ") ; print side_lengths_C_arr[index_1]
	*/
	append Angles_Arr Angle_B
	--format "Angles_arr = % \n" Angles_arr
 
	)
 
if spline_point != undefined then(
i = spline_point - 1 
if i<=0 then (
	while i <=0 do (
		i = i + (numknots spl s)
		format "you requested the angle corresponding to point % in the spline, the angle = % \n" spline_point Angles_arr[i]
		)
	)else(
 
 
			for x=1 to angles_arr.count do ( --go through angles_arr array and print out each angle and what point in the spline's angle it represents
				spline_point = x 
				i = spline_point - 1 
				if i<=0 then (
					while i <=0 do (
						i = i + (numknots spl s)
			)
		)
 
format "vert_num % has angle % \n" i Angles_Arr[i]
 
	)
)
 
 
)--end for s=1 to (numsplines spl) do
 
 
 
AttachmentSize
calc_spline_angles_23.ms 5.61 KB
Maarten's picture

Working on it :)

I'm writing some code atm, trying to figure it out will get back to you as soon as I have it done :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.