Tips for creating a straight line through the center of a sphere in ThreeJs

Imagine having a sphere similar to this:

const geometry = new THREE.SphereGeometry( 1, 32, 32 );
let sphere = new THREE.Mesh( geometry, material );
scene.add(sphere);

What would be the method to draw a line along the diameter of the sphere? Specifically parallel to the x axis. The ultimate aim is to utilize this line with text to demonstrate size (such as indicating that the sphere is 10m in diameter).

Answer №1

Here is a cool trick you can try out:

var material = new THREE.MeshBasicMaterial( { color: 0xaaaaaa } );
var geometry = new THREE.SphereGeometry( 32, 32, 32 );
var sphere = new THREE.Mesh( geometry, material );
scene.add( sphere );

var geometry = new THREE.TorusGeometry( 31.9, 0.16, 64, 100 );
var material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
var torus = new THREE.Mesh( geometry, material );
torus.rotation.x = Math.PI/2;
scene.add( torus );   

Check out this link for more details

Update: Another approach that may be better suited is the following:

var rad = 32,
    delta = 0.05,
    segs = 64,
    material = null,
    geometry = null,
    circle = null,
    sphere = null;

material = new THREE.LineBasicMaterial( { color: 0xffff00 } ),
geometry = new THREE.CircleGeometry( rad+delta, segs ),    
geometry.vertices.shift();
circle = new THREE.Line( geometry, material );
circle.rotation.x = Math.PI/2;
scene.add( circle );

material = new THREE.MeshBasicMaterial( { color: 0xaaaaaa } );
geometry = new THREE.SphereGeometry( rad, segs, segs );
sphere = new THREE.Mesh( geometry, material );
scene.add( sphere );  

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

Hello there, I'm currently attempting to use the Material UI IconButton along with an input ref to upload an image, but I'm experiencing some

click to view the UI image here Hi! I'm attempting to include a Material UI button to upload an image, but it's not functioning as expected. Below is the code snippet and a link to the sandbox where I'm trying to achieve functionality simil ...

JavaScript throws a "null is null or not an object" error when attempting to

I am dealing with a div that contains flash content in the form of Open Flash Chart. However, I encounter a javascript error when trying to remove child divs using $("#mydiv").children().remove() specifically in IE 8: The error message reads: "null is n ...

Employ the setInterval function to run a task every 15 minutes for a total of

I have a task that requires me to use setInterval function 5 times every 15 minutes, totaling one hour of work. Each value retrieved needs to be displayed in an HTML table. Below is the table: enter image description here For example, if it is 7:58 p.m. ...

Generating a JSON object on the fly in a React Native application

There have been similar questions asked in the past like this & this. After looking at those SO questions, I came up with this code. As a newcomer to React Native and Javascript, I am facing two issues. 1. I'm trying to structure my data like this ...

Optimal method for identifying all inputs resembling text

I'm in the process of implementing keyboard shortcuts on a webpage, but I seem to be encountering a persistent bug. It is essential that keyboard shortcuts do not get activated while the user is typing in a text-like input field. The approach for hand ...

Is it possible to use WebRTC on mobile browsers without downloading a separate application?

Is there a webrtc demonstration that functions smoothly on a mobile browser without the need for a native OS App for android and iOS? I came across a demo on Mozilla Hacks where they were able to establish a connection through a webpage portal. They even ...

Querying and Retrieving a List of Nested Documents in MongoDB

I have multiple solutions, each of which may contain various projects. To represent this relationship, I opted for embedding the projects within the solution document. For example: [{ _id: "1", solutionTitle: "Some Sample Solution", p ...

Node.js encountered an error due to a self-signed certificate within the certificate chain

I'm encountering an issue with client-side HTTPS requests. An example snippet is as follows: var fs = require('fs'); var https = require('https'); var options = { hostname: 'example.com', port: 443, path: & ...

Creating an HTTP request in Node.js and saving it to a file

Is there a way for me to save HTTP requests onto a file? My server is using Node.js. I am sending data via AJAX as shown below: user_info = { system_info: [ {'browesr': browser}, {'brower-version': ...

Difficulty in sharing cookies among subdomains

I have successfully stored my visitors' style sheet preference in a cookie, but I am facing an issue with sharing the cookie across subdomains. Even after specifying the domain, the cookie does not seem to be shared. What could be causing this proble ...

How to Refresh EJS Template in an Express Node.js Application

Currently, I am integrating discord.js with express and facing a challenge. I want my webpage to automatically update whenever the client.on("message") event is triggered. According to my knowledge and research, it seems that rendering an ejs template is o ...

Minimize the number of HTTP requests by including CSS and JS files in PHP

I've been considering a method to reduce the number of HTTP requests made when loading a page by minimizing the amount of downloaded files, while still keeping separate files on the server. The thought process is as follows: <!DOCTYPE html> &l ...

Animated mosaic pattern menu design

Is there a way to achieve this effect with a sketch? Note: I would like to add hover animation to the borders if possible. I attempted to do it using the following code: clip-path: polygon(0 0, 100% 0, 92% 86%, 6% 100%); However, the shapes created by ...

Creating TypeScript domain objects from JSON data received from a server within an Angular app

I am facing a common challenge in Angular / Typescript / JavaScript. I have created a simple class with fields and methods: class Rectangle { width: number; height: number; area(): number { return this.width * this.height; } } Next, I have a ...

Is there a way to pre-load images from component B within component A using Vue?

In a scenario where I have two Vue files, A.vue and B.vue, the issue arises when navigating from A to B. B contains numerous images fetched from Firebase realtime database, resulting in slow loading times upon first visit. To address this, I aim to preload ...

Node.JS encountered an issue preventing the variable from being saved

I've been attempting to store the request.headers, but every time it outputs as [object Object] in the txt file. var http = require("http"); url = require("url"); fs = require("fs"); var events = require('events'); var even = new events.Ev ...

What could be causing the PAGE CSS to malfunction?

I am looking to export HTML text as a word document with A4 size and portrait orientation. My JavaScript currently allows me to export the text, but it appears like a webpage format rather than in A4 or portrait mode. I have tried adding @page CSS styling ...

AngularJS and Rails: Error detected - provider 'e' is unknown

Upon transitioning to the production server utilizing Rails 4 and AngularJS, I encountered an error: [$injector:modulerr] Failed to instantiate module EcoApp due to: Error: [$injector:unpr] Unknown provider: e. After exploring various Stack Overflow thre ...

Steer clear of including optional dependencies when using Yarn for package installations

Within my yarn.lock file, there is a single reference to momentjs: pikaday@^1.6.0: version "1.6.1" resolved "https://registry.yarnpkg.com/pikaday/-/pikaday-1.6.1.tgz#b91bcb9b8539cedd8dd6d08e4e7465e12095671b0" optionalDependencies: moment "2.x" ...

Executing a separate function after each iteration of an ajax call within a loop using Jquery

I am faced with a situation where an ajax function must be run inside a loop that depends on the array's size. How can I execute another function after the ajax call is completed and outside the loop? Is this achievable? Below is the function: funct ...