The expected origin for the sine wave animation is not being met as intended

Experimenting with three.js, I am attempting to create an animation of a sine wave that originates from where a plane is clicked with the mouse. However, there seems to be a discrepancy in the ripple's starting point as it always emanates from the middle of the plane irrespective of the click location. Clicking towards the edges of the plane does alter the wave slightly, but the exact origin remains elusive.

Since math has never been my forte, I suspect there may be a logical error causing this issue!

Snippet:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
    </head>
    <body>
    </body>
    <script src="three.min.js"></script>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>
        // Insert your code snippet here
    </script>
</html>

The JSfiddle link for further exploration: https://jsfiddle.net/dwo3kvLp/

Answer №1

Removing the line where the plane is rotated (

plane.rotation.x = -0.5 * Math.PI;
) shows that it functions correctly.

The x, y, and z coordinates after rotation do not necessarily correspond to their intuitive directions. They refer to the old orientation, which may lead to confusion with user input coordinates. By adding a console.log statement to display wave.x, wave.y, and wave.z values, you can observe the problem in action.

Upon further examination, it becomes clear that the perceived "y" direction ("forward-backward") is actually governed by "z", leading to consistent movement left-right but fluctuating forward-backward. Adjusting the assignment of points to the wave can resolve this issue.

To fix the problem, modify these lines:

wave.y = intersects[0].point.y;
wave.z = intersects[0].point.z;

to

wave.y = intersects[0].point.z * -1;
wave.z = intersects[0].point.y;

This adjustment should rectify the issue at hand.

For the complete updated code, refer to:

(Updated code snippet)

Answer №2

After analyzing the code, it appears that switching the y and z axes in the creation of the center vector may be necessary:

var center = new THREE.Vector3(wave.x, -wave.z, wave.y);

This adjustment seems to be linked to a rotation of the plane at this point:

plane.rotation.x = -0.5 * Math.PI;

Link to example

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

Acquiring the API through the callback function within a React application

I wrote a function that connects to an API and fetches data: import {API_KEY, API_URL} from "./constants"; export const getOperations = async (id, successCallback) => { try { const response = await fetch(`${API_URL}/tasks/${ ...

What is the best way to extract data from a textarea HTML tag and store it in an array before iterating through it?

I have a project in progress where I am developing a webpage that will collect links from users and open each link in a new tab. I am using the <textarea> tag in HTML along with a submit button for link collection. Users are instructed to input only ...

Ways to determine whether an element is presently engaged in scrolling

Is there a way to determine if certain actions can be disabled while an element is being scrolled? The scrolling may be triggered by using the mouse wheel or mouse pad, or by calling scrollIntoView(). Can we detect if an element is currently being scroll ...

Is there a way to display incoming chat messages on the chat box without requiring a page refresh using socket.io?

Having trouble resolving an issue with my application hosted on wpengine, built using WordPress, vue.js, and socket.io for chat functionality. The main concern is that new messages posted in the chatbox do not display until the page is refreshed. I'm ...

Using Javascript to display or conceal a specific child element within a loop, based on which parent element has been clicked

I need assistance with creating a grid of projects where clicking on a specific 'project' in the loop will display the corresponding 'project_expanded' div, while hiding all other 'project_expanded' divs. My initial plan was ...

Trigger a JavaScript function on a body click, specifically targeting certain elements to be excluded

I have a dropdown menu within a div element. I've created a javascript function called HideDropdown() that hides the menu when any main link on the page is clicked, except for links within the dropdown menu itself: <script> function HideDropdow ...

The Handlebars helper needs to provide a result when a value is present

I have created a Handlebars helper function like this: Here is the code in my JavaScript file: Handlebars.registerHelper('switch', function (sw_val, options) { if (sw_val != '*NONE' && sw_val != false && sw_val != ...

Visualize data from ajax call in tabular format

I want to display the results of an SQL query in a table using AJAX. I have written code that executes the query during the AJAX call, but when I try to display these values in a table, it shows null values on the div tag. What could be the reason for this ...

Understanding the NavigationContainer reference in Typescript and react-navigation

In my current project with react-navigation, I've come across a scenario where I need to navigate from outside of a component (specifically after receiving a push notification). The challenge is that when I use the navigation.navigate method from wit ...

Using ES6 to Compare and Remove Duplicates in an Array of Objects in JavaScript

I am facing a challenge with two arrays: Array One [ { name: 'apple', color: 'red' }, { name: 'banana', color: 'yellow' }, { name: 'orange', color: 'orange' } ] Array Two [ { name: &apos ...

What's the best way in Angular 6 to set focus on an element that's being made content editable?

I am currently utilizing the contentEditable attribute in Angular 6 to allow for editing the content of elements within an ngFor loop. Is there a way to focus on a tag element when its contentEditable attribute is set to true? <div class="tag" *ngFor= ...

AngularJS and numerous parallel indexed tables side by side

I need help with displaying two tables, one for profiles and the other for rates. The rates are connected to profiles through the rate name in the JSON data. Is there a way to show these two tables side by side? And when a row is selected in the profile ta ...

What is the best way to extract multiple variables from a function in JavaScript?

After creating the function buttonEffects() with four different button effects, I am now facing the challenge of bringing these variables outside of the function and using them in another function. Is it possible to achieve this without recoding everything ...

Navigating to a new URL after submitting a form in React

Hello, I am new to React and have created a form that successfully sends data to Firebase. However, after submitting the form, I would like to redirect to /thankyou.html which is outside of the React app. Can someone please guide me on how to achieve this ...

Node.js bypasses unit test validation

As a beginner in BDD with Node.js, I have a controller function defined as follows: var getUser = function(username, done) { console.log('prints'); User.findOne({ 'local.username': username }, function (err, user) { ...

struggles with integrating arrays into object attributes in JavaScript

When working with object attributes, keep in mind that they only hold the first element of the assigned value let groupedDepActivities=[] groupedDepActivities.push({ id:1, term_activity:{ terms:[{id:1},{from:'her ...

Tips for updating the class name of a specific div element during runtime

I'm trying to dynamically update the class name for a specific div at runtime, and this div also includes support for image preview using JQuery. ...

Generating HTML content using JavaScript object data

I have a JavaScript file that holds data in the form of objects : let restaurant_A = { name: "BBQ place", min_order: 20, delivery_charge: 5, menu: { //First category "Appetizers": { //First it ...

Issues with broadcasting in React using Socket IO have arisen

Currently, I am developing a game using Socket IO where each room has its own channel of communication. The issue I am facing is that when a player places a bet, not only does the opponent receive the message, but the player themselves also receives it. B ...

Utilizing a custom filter for object manipulation within Vuetify's v-autocomplete

When using vuetify v-autocomplete with an object where the object consists of Key-Value pairs, the search functionality is based on the item-text. In my example, I am displaying the object as {1200-Chloride Systems}. Is it possible to make the search funct ...