Rotation to a point in a circle using three.js

Currently, I am in possession of 2 instances of THREE.Vector3().

My task at hand is to create a circular shape around one vector with the second vector serving as a tangent.

I have determined the radius of the circle geometry based on the distance between the two vectors.

How can I transform the circle in order for it to intersect with the second vector?

Moreover, how do I determine the rotation (in radians) of the circle?

Can I leverage functions within the THREE framework or would a mathematical approach be more suitable for this scenario?

(Ideally, I am hoping that there exists a fundamental function within the 3D framework).

Answer №1

When working with 3D vector graphics, a common trick is using 4x4 homogenous transform matrices

  • To achieve this effect, you create the matrix and apply it to the entire geometry
  • This process is typically handled on the graphics hardware side
  • In certain scenarios, you can skip calculating angles and simply compute the basis vectors

Below is my implementation of glCircle3D in C++/OpenGL:

void glCircle3D(double *pos,double *nor,double r,bool _fill)
    {
    // implementation details here...
    }
  • nor represents the circle normal (in this case, the second vector)
  • pos indicates the circle center position (0,0,0 in your scenario)
  • r denotes the radius (size of the first vector in your case)
  • x,y vectors serve as the basis vectors, orthogonal to nor
  • By copying x,y,nor,pos into the appropriate fields of the matrix, you can construct the transform matrix
  • No need for complex trigonometric functions like atan2 or acos(dot(v1,v2)), simple cross product suffices
  • My code leverages a custom vector library, which includes functions like vector_ld, vector_mul, vector_add, etc.
  • The circle coordinates are determined by the formula: p=pos+x*cos(alpha)+y*sin(alpha);
  • The radius r is already accounted for within the x,y basis vectors

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

Retrieving distinct items from an array containing nested objects and sub-properties

In my script, I am attempting to retrieve unique objects based on the state from an array of objects. The current script is functioning correctly for most cases. However, there is one scenario where a nested object in a specific state has a sub-state, and ...

What are the steps for adding node packages to sublime text?

Is there a way to install node packages directly from Sublime Text instead of using the command line? If so, what is the process for doing this? I'm not referring to Package Control; I'm specifically interested in installing npm packages like th ...

Numerous Switches Similar to Tabs Using JavaScript and CSS

I'm looking to create tabs that operate as toggles, but with the twist that only one toggle can be active at any given time. Additionally, I need the tab content to appear above the actual tabs themselves. The challenge lies in the fact that I am usin ...

Create a custom loading spinner for a jQuery AJAX request

How can I add a loading indicator to my Bootstrap modal that is launched from a link? Currently, there is a 3-second delay while the AJAX query fetches data from the database. Does Twitter Bootstrap have built-in functionality for this? UPDATE: Modified J ...

Using async/await with Middleware in Express

I'm struggling to grasp the concept of writing middleware in Express that uses async/await without leaving a floating Promise after execution. Despite reading numerous blogs and StackOverflow posts, it appears that there is a common pattern for utiliz ...

Having trouble identifying the issue with the dependent select drop down in my Active Admin setup (Rails 3.2, Active Admin 1.0)

I am currently working on developing a Ruby on Rails application that involves three models: Games that can be categorized into a Sector (referred to as GameSector) and a subsector (known as GameSubsector) A sector consists of multiple subsectors. A Subs ...

Transform the hue of symbols within D3-legend

I am attempting to modify the appearance of symbols in a legend. The variable below represents the available symbol types: var symbolTypes = { "triangleUp": d3.svg.symbol().type("triangle-up"), "circle": d3.svg.symbol().type("circle") }; I use this varia ...

Creating a new JavaScript object using a Constructor function in Typescript/Angular

Struggling with instantiating an object from an external javascript library in Angular/Typescript development. The constructor function in the javascript library is... var amf = { some declarations etc } amf.Client = function(destination, endpoint, time ...

Utilizing Dynamic Image Sources in Vue.js with the Help of APIs

Can someone help me figure out how to solve this issue? I have an API that returns a base64 image, and I want to load this image on my site. Any suggestions on where or how I should implement my function? This is the API call located in the methods: metho ...

Transform the object into an array of JSON with specified keys

Here is a sample object: { labels: ["city A", "city B"], data: ["Abc", "Bcd"] }; I am looking to transform the above object into an array of JSON like this: [ { labels: "city A", data: "Abc" }, { labels: "city B", data: "Bcd" }, ]; ...

Retrieving information in Ionic

Having trouble fetching data from a server in my first ionic application. I keep getting an error that says "Cannot read Property" while trying to attach my code snippet. Here is what my code looks like: import { Component } from '@angular/core' ...

Navigating with Vue Router in a Nuxt JS vuex Store

In my app, I'm currently developing a login/register system using Firebase and Vuex for authentication and database management. Within Nuxt JS, I have implemented actions to create a user, log them in, and sign them out. After a successful registrati ...

What is the significance of Fawn's statement, "Invalid Condition"?

Despite following the instructions and initiating Fawn as stated in the document, I'm still encountering an error message that says Invalid Condition. Can anyone help me identify what is causing this issue? Thank you to all the helpers. await new Fawn ...

Having trouble with your jQuery code not loading properly?

Currently working on debugging jQuery code and facing an issue where a particular section of the code is not being triggered upon clicking. The HTML/PHP in question: $cartlink .= "<a class='add_to_cart button' data-id='{$product->id} ...

Designing access to data in JavaScript

As I work on developing my single page app, I find myself diving into the data access layer for the client-side. In this process, a question arises regarding the optimal design approach. While I am aware that JavaScript is callback-centric, I can't he ...

The npm error message states: "Unable to locate the 'readable-stream' module."

Recently, I installed node js on my Windows 10 machine with version v4.4.2. However, whenever I attempt to run npm install or check npm version, it throws the following error message. Any assistance on this matter would be highly appreciated. Error: Canno ...

Loading information in a directive by utilizing promises in a service with AngularJS

Can anyone lend a hand? I've been struggling to solve this issue. I created a directive (see below) to display a pre-written ul-list on a page using html data fetched asynchronously from a database server. Both the Directive and The Service are funct ...

Angular mat-select is having difficulty displaying options correctly on mobile devices or devices with narrow widths

In my Angular project, I've encountered an issue with mat-select when viewing options on mobile or low-resolution screens. While the options are still displayed, the text is mysteriously missing. I attempted to set the max width of the mat-option, but ...

When _.template is evaluated in Node JS, it freezes and encounters a ReferenceError causing the program to halt

I've noticed a strange issue when using http://underscorejs.org/ with Node JS: If a reference error occurs while evaluating a template function, Node JS will become unresponsive! Examples: EXAMPLE 1: SUCCESSFUL SCENARIO: var template = "<%= tes ...

What is the best method for creating and passing a wrapped component to React Router?

I have multiple routes that I need to render different components for, and I want each component to be wrapped in a styled div. However, I'm looking for a way to write this code more efficiently. Is there a strategy to refactor this so that I can eas ...