Apply geometric principles to the physical world

In an attempt to accurately scale my geometry to match real-world dimensions in my 3D scene, I am facing some challenges.
I extract the coordinates of the top left and top right corners of my map, convert them into points using Google Maps projection, and calculate the difference between these points to determine the map's delta.
Next, I divide this delta by the deltaX of my geometry's bounding box.
However, the current code implementation is not yielding the desired scaling results.
When zooming in on the map, the scale decreases, while zooming out increases the scale - which is opposite of what is expected.
Moreover, I am unsure if this approach accurately reflects real-life scaling.

The current process involves:

var bounds = MAP3D.map.getBounds();
var projection = MAP3D.map.getProjection();

var x1Length = projection.fromLatLngToPoint(new google.maps.LatLng(
    bounds.getNorthEast().lat(),
    bounds.getSouthWest().lng()
));
var x2Length = projection.fromLatLngToPoint(new google.maps.LatLng(
    bounds.getNorthEast().lat(),
    bounds.getNorthEast().lng()
));
var ThreeUnitsX = Math.abs(x2Length.x - x1Length.x);


if (
    MAP3D.ObjectManager.WellList[i].LOD.objects[0]
        .object.geometry.boundingBox == null
) {
    MAP3D.ObjectManager.WellList[i].LOD.objects[0]
        .object.geometry.computeBoundingBox();
}

var boundingBox = MAP3D.ObjectManager.WellList[i].LOD.objects[0]
    .object.geometry.boundingBox;

var deltaX = boundingBox.max.x - boundingBox.min.x;
var scaleX = ThreeUnitsX / deltaX;

me.WellList[i].LOD.scale.set(scaleX, scaleX, scaleX);

I extend my gratitude to chandlerp from the #THREE.JS irc channel for invaluable assistance.

Answer №1

When calculating the scale, make sure to adjust for the desired object length. For instance:
var scaleX = deltaX / ThreeUnitsX;

However, this calculation assumes that your object should always be 111km long.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Encountered a TypeError stating that Object(...) is not being recognized as a function" while attempting to import a function via a barrel

In one of my files, I have a function named merge which has the following code inside: export default (prev, next) => Object.assign({}, prev, next) Additionally, there is a barrel file that imports and exports this function like so: import fetchToNode ...

Arranging an array based on relationships between children and parents

I have an array of objects like this: const data = [{id: 3, name: ''}, {id: 4, name: ''}, {id: 5, name: '', parent: 3}, {id: 6, name: '', parent: 5}, {id: 7, name: '', parent: 4}, {id: 8, name: '&ap ...

retrieve JSON information using JSONP

Currently, I am working with a URL that returns data in JSON format. Here is the URL: http://10.0.1.11/render?target=threshold(400,test)&from=-1mins&format=json&jsonp=? When I enter this URL into a browser, it displays the following JSON re ...

Struggling to adjust the width of a div accurately following the population of AJAX content

This particular piece of code is responsible for populating an inner div within an image slider by making an Ajax call : $.ajax({ type: "GET", dataType: 'json', url: $(this).attr('href') }).done(function (result) { ...

How to retrieve URL parameters from within the when() function in AngularJS

Consider the code snippet below: $routeProvider.when('/movies/:type', { title: 'Movies', templateUrl: 'pages/movies/movies.html', controller: 'MoviesCtrl' }); Is there a way to retriev ...

Wondering how to modify an image source when clicked using javascript and css?

I am looking to create a menu button labeled "menu" that rotates around using rotateX, and then changes into the text "close". Initially, I attempted to achieve this effect with text and animation, followed by text and transform. When those methods failed, ...

What is a straightforward method to display one Div while concealing all others?

Is there a simpler method to display one div and hide all others, with the first one shown by default? My current solution using jQuery works, but it feels lengthy. I believe there might be a more efficient way to achieve this. Here is the code snippet: ...

JavaScript Error: String length or allocation size is not valid

My code consists of a series of checkboxes that need to be checked, then if they are checked, a string is added to an array. The goal is to loop through the array and concatenate the strings with commas in between. Unfortunately, every time I run this, err ...

Is there a way for ASP.NET MVC to automatically notify when a record is edited or updated?

Having recently used the NotifyIcon class in a windows application, I found it to be quite useful. As someone who primarily works as a web developer, I am curious if there is something similar available for websites. The website that I am working on inclu ...

Having difficulty accessing the value of a table td element in HTML using a jQuery selector

When creating a table, I utilize ng-repeat to generate table rows. Whenever the dropdown changes, a function is triggered which applies certain conditions. Based on these conditions, an object is added to an array that is bound to a scope variable. Here i ...

The button text in Bootstrap 5 is black instead of white as shown in their demo

During the installation of Bootstrap 5, I encountered an issue where many of my buttons are displaying a black font instead of the expected white font as shown in the Bootstrap 5 Documentation For instance, the .btn-primary button on the official Bootstra ...

AngularJS enthusiasts have the ability to curate a personalized list of favorites

I am looking to implement a feature in my application where users can create a favorite list based on their selection. The application utilizes a lengthy JSON file containing a multitude of text, which is loaded using $http.get(). Below is the code segment ...

Unable to properly cancel a post request using abort functionality

In the process of building a Next.js app, I encountered an issue with calling a post request. I included a cancel button to halt the post request, and attempted to use abortController in conjunction with Axios (v1.4.0) to achieve this. Even though the &ap ...

Components for managing Create, Read, Update, and Delete operations

As I embark on my Angular 2 journey with TypeScript, I am exploring the most efficient way to structure my application. Consider a scenario where I need to perform CRUD operations on a product. Should I create a separate component for each operation, such ...

Is it possible to create an array that organizes monthly income data from a JSON file?

I'm currently developing an Accounting System where I need to display a bar chart showing the monthly Incomes and Expenses. The data is retrieved from a database using AJAX, and it returns the following JSON: { "results":{ "his ...

Finding the data type based on the button clicked with javascript: A beginner's guide

I am trying to work with a PHP function that generates dynamically created divisions. Each of these divisions contains a different data type and a button. How can I extract the data type of a division when the user clicks on the submit button using JavaScr ...

Tips for incorporating a variable into a JSON object value when dynamically constructing an object

Is there a way to dynamically create an array of objects using a for loop? I have different arrays with values for the key value pairs of these objects. The code snippet I tried is not producing the expected result. var characters = ['Iron Man', ...

Leveraging Vue.js plugin within a single file component

I am looking to utilize the vue-chartkick plugin in my Vue application, but I want to register it within my single-file components instead of globally. Is there a way to achieve this same functionality without using Vue.use(VueChartkick, { Chartkick })? ...

Retrieving a page using jQuery

Below is the JavaScript code that I am using: $.ajax({ url: "test.html", error: function(){ //handle error }, success: function(){ //perform actions here with the received data } }); After retrieving test.html, I am wo ...

md-input container displays content only upon user interaction

Currently, I am working with AngularJs 1 and Angular-Material Design. One issue I encountered was with a md-input container used for file uploading. The problem I faced was that even after selecting a file, it wasn't being displayed in the md-input co ...