Circular movement in ThreeJS within a specified duration

I am currently working on creating a circular motion for an object within a set time frame.

This project involves designing a clock with smooth motion.

Instead of simply updating the position to fixed coordinates every time .getSeconds() changes, I aim to use a combination of

(.getSeconds() + (.getMilliseconds()/1000)
to accurately display the movement of the second hand continuously.

In previous projects involving circular motion, I utilized the following pair of functions:


var OrbitCalculationX = function(velocityPartial, orbitalRadius) {
    return (Math.sin(Date.now() / 16000 * velocityPartial) * orbitalRadius);
};
var OrbitCalculationZ = function(velocityPartial, orbitalRadius) {
    return (Math.cos(Date.now() / 16000 * velocityPartial) * orbitalRadius);
};`

The value 16000 in that calculation determined the orbital time, but it was not accurate. Is there a method to control a x-axis sin vs z-axis cos equation pairing with precise time constraints?

If not, is there a way to define an animation path to complete within an exact timeframe using THREEjs?

Answer №1

Hopefully, my interpretation is accurate...

Consider a minute divided into 60 seconds and 60,000 milliseconds. The initial step involves obtaining values within this range.

var millisInMinute = Date.now() % 60000;

Next, we must standardize the value to a 0 to 1 scale:

var millisInMinuteNormalized = millisInMinute / 60000;

To create a full circular motion using sine and cosine functions with our variable ranging between 0 and 1, we multiply it by 2*PI see plot here

The remaining calculation involving the radius follows similar principles as demonstrated earlier, resulting in

var orbitCalculation = function(radius) {
    return {x: (Math.sin((Date.now()%60000)/60000 * Math.PI * 2) * radius),
            z: (Math.cos((Date.now()%60000)/60000 * Math.PI * 2) * radius)};
}

The current time displayed accurately can be cross-referenced with your system clock. See a working JSFiddle

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

Executing certain test suites with defined capabilities in Protractor

My website is designed to be compatible with both desktop and mobile browsers, each having its own unique user interface. In my protractor config file, I have some suites that need to be tested using the desktop user agent, while others require testing usi ...

Revamp the layout of the lower HTML video menu

Here is my code: <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> video { width: 100%; height: auto; } </style> </head> <body> <video width="400" controls> ...

Removing values when disabling a button using JavaScript

Within my code, I have two tables - one for non-clickable teams and another for clickable matches. Check out the image of the tables View the code on my GitHub repository let teams = [ {name: 'Roma', points: 0, wins: 0, draws: 0, loses: ...

Angular ui router - Transitioning from one state to the same state, when no parameters are provided, results in

Check out the Plunker Demo <script> var myapp = angular.module('myapp', ["ui.router"]) myapp.config(function($stateProvider, $urlRouterProvider) { // If there is no matching URL, go to /dashboard $urlRouterProvider. ...

What are the steps to retrieve marker data from a MySQL database and showcase them dynamically on a Google Map using AJAX? Addressing time constraints

Utilizing a combination of JavaScript, Google Maps API, PHP, and MySQL, my app is designed to extract a list of markers from a MySQL database, export them to a myXML.xml file, and then load these markers onto the map each time it loads. <!DOCTYPE html& ...

Ways to conceal the lower details in DataGrid Material-UI

Utilizing the DataGrid component from MUI and I'm eager to conceal this element. Any suggestions on how I can achieve this? Thanks! https://i.sstatic.net/2YG9s.png ...

What could be the reason for the malfunctioning of my React Native vector icons?

My react native vector icons are not working despite following all the steps mentioned in the documentation. I am unable to use a camera icon in my app. I tried importing { Entypo } from 'react-native-vector-icons'; and then using \<Entyp ...

Fetching information with request query parameters in Node.js

Working on implementing email verification using nodemailer for user sign-ups. The process involves sending out an email containing a link (usually something like localhost:3000/verify/?id=##). After the user clicks the link, I can see that a GET request ...

The router is unable to direct when an item is clicked

I am encountering an issue with my routing setup - when I click on an item in the list-item component, it does not successfully route to the detail-component. Here is a glimpse of my source code: product-list.component.html: <h1>Product List Compon ...

Encountering a 500 server error while trying to send an email using SendGrid in conjunction

Seeking help on integrating an email capture form into a NextJS site by following this tutorial: Simplified the form to only include the email field. The content of my api/contact.js file is as follows: const mail = require('@sendgrid/mail'); ...

What is the process of converting an Array that is nested within an Object?

I am facing compile errors while attempting to convert an Object containing an Array of Objects. Here is the initial structure: export interface CourseRaw { metaInfo: MetaInfoRaw; gameCode: number; gameText: string; images?: ImageRaw[]; // Having ...

Differentiating Typescript will discard attributes that do not adhere to an Interface

Currently, I am working with an API controller that requires a body parameter as shown below: insertUser(@Body() user: IUser) {} The problem I'm facing is that I can submit an object that includes additional properties not specified in the IUser int ...

jquery accordion failing to display content

Upon navigating to my website and accessing the webpage featuring an accordion, the accordion successfully appears and hides after 1500ms as intended. However, when attempting to reveal the text by clicking on the headings, nothing happens. The heading sim ...

Issues with routing in NodeJS Express causing routes to not be called

I've been working on setting up a basic REST API using nodeJS. However, I am facing an issue where none of the endpoints are being called when I try to access them. Can someone guide me on what changes I need to make in order to get it working properl ...

"Enhance your website with a dynamic Jssor slider featuring nested slides and vertical

Exploring the idea of merging the nested slider feature with a vertical thumbnail display. Reviewing the source code for examples image-gallery-with-vertical-thumbnail.source.html and nested-slider.source.html, I am wondering how to effectively combine t ...

The dispatch function in redux-thunk is not functioning as expected

Having trouble with thunk and async dispatching? Check out this code snippet: function fetchProvider() { return (dispatch) => { graphqlService(fetchProviderQuery) .then((result) => { dispatch({ type: FETCH_PROVIDER, ...

Troubleshooting problems with Three.js at tiled texture edges when using MeshFaceMaterial

I've been working on tiling textures from multiple images onto a plane geometry using MeshFaceMaterial. Everything seems to be functioning correctly, except for a noticeable blurry edge that forms between the tiles. var textureArray = []; ...

Store text in a table format in your local storage

I need help figuring out how to save product and price information to local storage when an "add to cart" button is pressed. Can someone provide guidance on how to do this? Here is the code I currently have: body> <!-- Header--> ...

"Including Span icons, glyphs, or graphs within a table cell in AngularJS based on a specified condition or numerical

I'm attempting to incorporate span icons/glyph-icons using Angular within a td before displaying the country. I've utilized the code below to achieve this, but I'm looking for a more dynamic and elegant solution. Your assistance is greatly a ...

Can the color of text be adjusted (to either white or black) based on the background color (in any color and format)?

To achieve a text color that contrasts well with any background, I need to make sure it's either black or white. The background in my app can vary in color and format, so finding the perfect solution has been challenging. Using mix-blend-mode doesn&a ...