exchanging a library for a different one

I'm faced with a relatively simple task here, but as I am just beginning to delve into object-oriented programming, it is proving to be quite perplexing for me. Currently, I am using the lon_lat_to_cartesian function from the following source:

function lonLatToVector3( lng, lat, out )
{
out = out || new THREE.Vector3();

//flips the Y axis
lat = PI / 2 - lat;

//distribute to sphere
out.set(
            Math.sin( lat ) * Math.sin( lng ),
            Math.cos( lat ),
            Math.sin( lat ) * Math.cos( lng )
);

return out;

}

Within my glmain.js file, I invoke it using the following line:

position = lonLatToVector3(data.latitude, data.longitude);

Essentially, the latitude and longitude points are transformed into a vector through this process.

Now, I am looking to replace this library with latlon-vectors.js. I am particularly interested in using the lines 50-60 from the code:

LatLon.prototype.toVector = function() {
var φ = this.lat.toRadians();
var λ = this.lon.toRadians();

// right-handed vector: x -> 0°E,0°N; y -> 90°E,0°N, z -> 90°N
var x = Math.cos(φ) * Math.cos(λ);
var y = Math.cos(φ) * Math.sin(λ);
var z = Math.sin(φ);

return new Vector3d(x, y, z);
};

As per my limited understanding, this seems to be a method of the main object:

function LatLon(lat, lon) {
// allow instantiation without 'new'
if (!(this instanceof LatLon)) return new LatLon(lat, lon);

this.lat = Number(lat);
this.lon = Number(lon);
}

While I could easily call this function by doing:

position = LatLon(data.latitude, data.longitude);

This wouldn't achieve my goal of converting the Lat, Lon points to a vector. How can I proceed to invoke the aforementioned lines(50-60)?

Answer №1

Examining the content of latlon-vectors.js, to convert latitude and longitude into a vector, you must use the following code:

const location = LatLon(data.lat, data.lon);
const vector = location.vectorize();

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

Is PHP loaded prior to the `html body`?

I'm facing a unique challenge where I am currently transferring variables from a PHP page to hidden HTML inputs. The values are extracted from these hidden inputs using a JavaScript function that is called in the following manner: <body onload=" ...

Pattern matching: Identify text elements specifically within an HTML tag

I've been experimenting with a text highlighting script. Check out my initial attempt here. Here's the code snippet: http://jsfiddle.net/TPg9p/3/ However, I encountered a problem – it only works with simple strings and not those containing HT ...

What is the best method for establishing a page location during rendering/onload?

It seems like there is a JavaScript event happening here using the onload attribute. But for the life of me, I can't seem to crack this code. <body onload="moveToHere('reference')"> I'm stuck and could really use some assistance ...

Modifying the scope variable does not trigger an update in the AngularJS directive

Recently, I created a small directive that wraps its contents with another template file. The objective is to transform the code like this: <layout name="Default">My cool content</layout> into this output: <div class="layoutDefault">My ...

Avoiding the creation of a history entry while switching languages on a Next.js website

I'm currently developing a Next.js project that includes a language dropdown feature for users to choose their preferred language. In the existing setup, we are utilizing the router.push method from next/router to update the language selection and red ...

Exploring the journey of the three.js editor: Unraveling the process of converting commands into a

Even though I'm a seasoned web developer, I am relatively new to the world of 3D development. The capabilities of my models in the three.js editor have truly impressed me. One feature that caught my attention is the ability to "rewind" actions by sim ...

Refreshing PHP Script

I have a PHP file that contains a combination of HTML elements, JavaScript functions, and PHP scripts. I need to rerun a specific part of the PHP script repeatedly. Let's consider the following example: <html> <?php $connection = ...

Modify the parent div's background color on mouseover of the child li

I want to update the background image of a parent div that contains a series of ul li elements. Here is the HTML code I am working with: <section class="list" id="services"> <div class="row"> <ul> <li>& ...

Conceal a column within a table by double-clicking

I'm working on a project with a table, and I'd like to implement a feature where a column hides when double-clicked. I've seen various solutions for hiding columns on Stack Overflow, but I could use some guidance on where to add the ondblcli ...

The latest images are now visible in the table alongside the existing images that were previously added

When inserting images here, previously added images are displaying. Any solutions? Here is my view page <div class="col-md-2"> <form enctype="multipart/form-data" method="post" action="<?php echo base_url();?>admin_control/upl ...

Add a fresh text field with the click of a button and delete it with another button in Laravel 4

My form includes two fields: phone and email, as shown in the image below. By clicking on the plus button, I would like to add an additional text field to the form below the button. Similarly, by clicking on the minus button, I want to remove the text fie ...

Unable to load asset and playback animations with ObjectLoader

When it comes to exporting animated models, I have been using the single mesh export method and loading it with the JSONLoader. I followed a tutorial at , which worked perfectly for me. For scenes with multiple meshes, I export the full scene (selecting S ...

The intricacies of how Node.js handles asynchronous execution flow

I wanted to ask about the best approach for displaying data retrieved from MySQL. Do you think this workflow is correct? app.get('/demo/:id', function(req, res) { var query = csql.query('SELECT * FROM table_videos WHERE id=? LIMIT 1' ...

Converting object values to strings is a common practice during JSON posting operations

I encountered an issue with a date object when sending it to a NodeJS server. While the object is still preserved, the time gets converted to a string during the process. Is there a way to prevent this conversion? I tried parsing the object but received an ...

Encountering an unexpected token in the JSON file at the very start is causing an

An unexpected error has occurred, showing the following message:- Uncaught SyntaxError: Unexpected token u in JSON at position 0 The code causing the error is as follows:- import { useEffect, useState } from "react"; import { useNavigate, usePar ...

The sole focus is on the animation within the div

Is it possible to have a circle animation within a button without overlapping it? Check out my code on this fiddle. $(document).ready(function(){ $('button').on("mouseup",function(){ $('#mousemark').removeClass("c ...

Issue with SideNav function in MaterializeCss following recent update

After updating the css/js files of the Materializecss design in my project from v0.97.5 to v0.97.8, I noticed that my SideNav isn't functioning correctly anymore. When I try to click on the menu, it slides out but the dark overlay covers the entire sc ...

The AngularJS beginner routing application is malfunctioning and needs fixing

I've been diving into Angular JS but hit a roadblock with a basic angular routing program. I need some guidance on what's going wrong. If you want to check out the complete project code, visit my GitHub repository: https://github.com/ashpratap00 ...

A guide to accessing the currently hovered element on a Line Chart with Recharts

Just diving into this community and also new to ReactJS :( https://i.stack.imgur.com/k682Z.png I'm looking to create a tooltip that displays data only when hovering over the value 1 line. Unfortunately, the current tooltip is not behaving as expecte ...

Creating a code script for the purpose of automating npm commands

Currently, I am immersed in an angular js project and I have a desire to streamline the execution of the following two commands. ./node_modules/protractor/bin/webdriver-manager update ./node_modules/protractor/bin/webdriver-manager start The challenge li ...