Is there a way to generate spheres in threejs where the radius increases while always passing through a single point at 0,0,200? This would allow the origin of each new sphere to move along the z-axis.
Appreciate any help, AriemWebgl
Is there a way to generate spheres in threejs where the radius increases while always passing through a single point at 0,0,200? This would allow the origin of each new sphere to move along the z-axis.
Appreciate any help, AriemWebgl
To create a "parent" Object3D and connect the spheres to it, simply use the following code:
var sphereParent = new THREE.Object3D();
var numOfSpheres = 8;
for(var j = 0 ; j < numOfSpheres; j++)
{
var radiusSize = 10 + j;
var sphereGeo = new THREE.SphereGeometry( radiusSize, 16, 8 );
var sphereMat = new THREE.MeshLambertMaterial( { color: 0x0000ff } );
var nextSphere = new THREE.Mesh( sphereGeo, sphereMat );
sphereParent.add( nextSphere );
}
sphereParent.position.set(0,0,200);
scene.add(sphereParent);
In my opinion, all it takes is the creation of a few meshes and adjusting their positions:
let numberOfCylinders = 10;
for(let j = 0 ; j < numberOfCylinders; j++){
let height = 15 + (3*j);//increment the height based on the counter
let cylinder = new THREE.Mesh( new THREE.CylinderGeometry( 5, 5, height, 32 ), new THREE.MeshPhongMaterial( { color: 0xee3333, shininess: 100, wireframe:false } ) );
cylinder.position.z = -100;//or cylinder.position.set(0,0,-100);
scene.add( cylinder );
}
This age-old conundrum may have been resolved long ago, but since it remains unanswered, let's shed some light on it for future readers...
The number of spheres with a radius R
sharing a common surface point P
is equivalent to the surface area of a sphere with a radius R
centered at P
, which is 4πR²
. This is because their centers are points on the same sphere centered at P
:
In scenarios like the one presented in this question, involving internally tangent spheres, mathematical calculations reveal that the center of the updated sphere (C₁
) will lie along the direction between the shared point (P
) and the original sphere's center (C₀
), at a distance equal to the difference in their radii (R₁ - R₀
) from the latter (C₀
):
When dealing with positional and directional vectors, it's important to understand:
Hence,
position(C₁) = position(C₀) + direction(P, C₀) * (R₁ - R₀)
. Alternatively, for a more concise solution using Three.js, we can directly update via position(C₀) += normalize(C₀ - P) * (R₁ - R₀)
and scale by R₁ / R₀
, as shown below:
sphere.position.addScaledVector(sphere.position.clone().sub(point).normalize(), newradius - oldradius);
sphere.scale.setScalar(newradius / oldradius);
Note: Circles were used in the illustrations for simplicity, but imagine them as cross sections through the spheres' midpoints if it helps. The method described above applies to any point in any given position—it doesn't have to be restricted to the Z-axis or even confined to the sphere surfaces.
I'm struggling to get Vue testing set up with vue-test-utils and jest. I followed the installation guide at https://vue-test-utils.vuejs.org/installation/#semantic-versioning, but can't seem to figure out what's wrong. Here's what I&apo ...
In my application, I have integrated Google Maps which triggers a call to the backend every time there is a zoom change or a change in map boundaries. With a database of 3 million records, querying them with filters and clustering on the NodeJS backend con ...
I have encountered a challenge where I am unable to perform a small task. My goal is to have the position of "div1" change upon clicking on "div2", taking into account that "div2" is nested inside "div1". Additionally, when clicking on "div2" again, "div1" ...
Can someone please assist me with a hash map issue I'm encountering in my for loop? When resetting the second object, it unintentionally alters the Map values of the previous Key in the Hash Map. Any guidance on how to prevent this behavior would be g ...
After experimenting with different browser compatibility, I have discovered a way to clear all fields when clicking the "New" button. By using the code onClick="history.go(0)", the fields are successfully emptied in IE but unfortunately fail in Mozilla. ...
Currently, I have a script set up to display a map with two markers. Whenever I hover over one of the markers, a popup tooltip appears with location information. My question is, how can I make the information appear by default without needing to hover ov ...
Here is my HTML form: <form method="POST" enctype="multipart/form-data" v-on:submit.prevent="handelSubmit($event);"> <div class="clear"> <div class="col-md-3"></div> <div class="col-md-6"> <div class="form ...
I enjoy loading an external JavaScript file every 10 seconds, or whenever the page body is clicked (in which case, the script should only run if a few seconds have passed). If you could provide me with some documentation on this topic, that would be grea ...
Just starting out with angular and facing a seemingly simple issue that I can't seem to solve despite trying various solutions found on SO. I have created a login component where upon submission, the user is redirected to their profile page. While I a ...
I am currently researching whether I can achieve the functionality described in the title. Here are my initial thoughts: Let's consider the following routes I have set up: .when('/', { templateUrl : 'partials/homepage.html&ap ...
I attempted the solutions provided in the suggested duplicate question, but unfortunately, they did not yield the desired outcome. I have been struggling to utilize AJAX to POST data to a remote server's API from a local PC client (testing on Chrome ...
After implementing the code below on my page, I expected guests to be redirected to the main page post login and greeted with a small pop-up modal containing a thank you message. However, despite trying multiple variations of this code, it doesn't see ...
The script below, taken from a tutorial by Adam Khoury, is designed to create a timer that displays a message once it reaches completion. While I grasp the overall functionality of the code, I'm puzzled by the use of strings in certain parts: 1) Why ...
Is it possible to have two view model functions in my JavaScript where one references the other? I am encountering an error with this setup. Here are my view models: var userViewModel = function (data) { var _self = this; _self.ID = ko.obs ...
Below is the Update Panel that I am working on: <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="d ...
I need to create a feature where hovering over a row in the first table will highlight a corresponding row in the second table. The highlighting should be based on the index of the hovered row. Here is an example: <div> <table> < ...
I am working with structured data that looks like the example below: const arr = [{ id: 0, name: 'Biomes', icon: 'mdi-image-filter-hdr', isParent: true, children: [{ id: 1, name: 'Redwood forest& ...
I'm finding this task to be quite challenging, as I am struggling to comprehend it fully at the moment. The issue involves nested forEach loops, and I require a callback function to execute once all the loops have finished running. I am considering u ...
Currently, I am encountering an issue while attempting to duplicate a JSON array within this specific JavaScript function: var test = new array(); function showUser(user, pass, remember) { $.getJSON("login.php", { username : user, password : pass, che ...
The request is sent from an external source beyond my control xyz.php <form action='https_:_//xyz.com/javascriptFile' method='POST'> <input type='text' name='data' /> </form> to: (My custom f ...