Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script>
<script type="importmap">
  {
    "imports": {
      "three": "https://unpkg.com/three@0.155.0/build/three.module.js",
      "three/addons/": "https://unpkg.com/three@0.155.0/examples/jsm/"
    }
  }
</script>
              
            
!

CSS

              
                body {
  overflow: hidden;
  margin: 0;
}

              
            
!

JS

              
                // https://discourse.threejs.org/t/translating-geocoordinates-to-local-x-z-coordinates/55963

import * as THREE from "three";

console.clear( );


// PA, PB and PC are three points defined by their longitude
//				and latitude THREE.Vector3(longitude,0,latitude)
// QA and QB are two points in a coordinate system that has
//				the same handedness, e.g. either THREE.Vector3(x,0,z)
//				or THREE.Vector3(z,0,x). QA and QB correspond to
//				PA and PB
// Result: a the position of the third point QC that corresponds
//				to point PC

function geoLocal( PA, PB, PC, QA, QB )
{
		// calculation how much the latitude is scaled towards the poles
		var k = Math.cos( THREE.MathUtils.degToRad((PA.z+PB.z+PC.z)/3) );	
	
		// adjust the global coordinates
		PA.z /= k;
		PB.z /= k;
		PC.z /= k;

		// define vectors between points
		var PAB = new THREE.Vector3().subVectors( PB, PA ),
				PBC = new THREE.Vector3().subVectors( PC, PB ),
				QAB = new THREE.Vector3().subVectors( QB, QA );

		// calculate the length of vector QBC (its direction in unknown)
		var QBClen = QAB.length() * PBC.length()/PAB.length();

		// calculate the signed angle between vectors PAB and PBC
		// math explanation: https://stackoverflow.com/a/33920320
		var N = new THREE.Vector3( 0, 1, 0 ),
				V = PBC.clone().cross( PAB );
	
		var alpha = Math.atan2( V.dot(N), PAB.dot(PBC) );
	
		// get the QAB vector, normalize it and rotate it as
		// much as is the signed angle between PAB and PBC
		QAB.normalize().applyAxisAngle( N, -alpha );

		// expand the rotated vector to be as long as QBC
		// should be; add it to QB -- this is the point QC
		return QB.clone().addScaledVector( QAB, QBClen );
}



var P = geoLocal(
	new THREE.Vector3(144.30724288969,0,-38.1495921086427),// lon1, 0, lat1
	new THREE.Vector3(144.307338593531,0,-38.1492866772213),// lon2, 0, lat2
	
	//new THREE.Vector3(144.3073613926176,0,-38.14901617699974),// lon3, 0, lat3 -- sample point 1
	//new THREE.Vector3(144.30823108398587,0,-38.14923334727532),// lon3, 0, lat3 -- sample point 2
	new THREE.Vector3(144.30748132466096,0,-38.14995687807887),// lon3, 0, lat3 -- sample point 3
	
	
	new THREE.Vector3(12.62,0,-2.34),// z1, 0, x1
	new THREE.Vector3(11.2,0,-3.28)// z2, 0, x2
)

console.log( P.x, P.z )

              
            
!
999px

Console