Clothoid 2 point curve script

 From:  Michael Gibson
5878.8 In reply to 5878.6 
Hi Brian, ok so I think the problem is the script is not quite getting the correct 2D coordinates for doing your calculations.

At the start of your function buildClothoid you've got some calls to cplane.evaluate() there - but that's probably not right, you use cplane.evaluate() for converting from the frame's "local coordinates" into world coordinates.

At that point in the script for buildClothoid() you actually need the reverse I think - the points given to you by the pointpicker are in world coordinates and you want to get them into 2D coordinates within that cplane's local coordinate system before you start doing calculations with them. Then when you're done doing your calculations that's when you want to use cplane.evaluate() to convert from 2D local cplane coordinates back into world coordinates.

The .evaluate() call is only for doing the last part (2D local into 3D world conversion) - you need something different for the first part (3D world into 2D local cplane conversion).

For doing the 3D world into 2D local conversion you can get the local 2D plane coordinate from a 3D world coordinate by doing cplane.distancex() and cplane.distancey() which get the signed distance of the given 3D point from the x-axis plane and y-axis plane of the frame, something like this:

var localx = cplane.distancex( worldpt );
var localy = cplane.distancey( worldpt );

So if you use that in the start of buildClothoid() it should then give you uniform behavior in all views, here's an updated buildClothoid function that should work:


code:

function buildClothoid(BasePt, theta0, OtherPt, theta1, numintervals, cplane)
{
//Convert to cplane frame.
	var base_x = cplane.distancex( BasePt );
	var base_y = cplane.distancey( BasePt );
	
	var other_x = cplane.distancex( OtherPt );
	var other_y = cplane.distancey( OtherPt );
	
	var deltax = other_x - base_x;
	var deltay = other_y - base_y;
	var r = Math.sqrt( (deltax * deltax) + (deltay * deltay) );
	var phi = Math.atan2(deltay, deltax);
	var deltaphi = normalizeAngle(theta0 - phi);
	var deltatheta = normalizeAngle(theta1 - theta0);
	
	var Aguess = 2.4674 * deltatheta + 5.2478 * deltaphi;
	var A =	findA(Aguess, deltatheta, deltaphi);
	var a = 0.0;
	var b = 1.0;
	var maxR = 50; //maxrecursion
	var L = r/ adaptiveSimpsons(A, deltatheta, (deltaphi + Math.PI/2), a, b, maxR );	
	var K =	(deltatheta - A) / L;
	var Kprime = (2*A)/(L*L);
	
	return 	{ 'K': K, 'Kprime': Kprime, 'L': L };
}	



Hope this helps!

Looks like some cool stuff! I wish I had more time to experiment with some stuff in this same area as well myself.

- Michael