Create a dynamic prism that adjusts its size according to the distance

I am interested in creating a drawing of an octagonal prism that can also be oblique, with variable face shapes and heights depending on edge lengths. Where should I begin?

Is it possible to use a function to calculate the coordinates of base B while considering that base A is fixed?

https://i.sstatic.net/v6zqx.png.

PS: Base A and base B are equal.

Answer №1

To determine the outcome, it depends on the type of geometry that is utilized. To illustrate, here is a demonstration using a traditional geometry (THREE.CylinderGeometry()):

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 2, 10);
var renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

var controls = new THREE.OrbitControls(camera, renderer.domElement);

scene.add(new THREE.GridHelper(10, 10));

var prismGeom = new THREE.CylinderGeometry(1, 1, 4, 8, 1);
for(let i=0; i< 8;i++){// upper base
  prismGeom.vertices[i].y = 1 + THREE.Math.randFloat(-1, 1);
}
prismGeom.vertices[prismGeom.vertices.length - 2].y = 1 + THREE.Math.randFloat(-1, 1);// center of the upper base
prismGeom.translate(0, 2, 0);

var prism = new THREE.Mesh(prismGeom, new THREE.MeshBasicMaterial({color: "yellow", wireframe: true}));
scene.add(prism);

render();

function render() {
  requestAnimationFrame(render);
  renderer.render(scene, camera);
}
body {
  overflow: hidden;
  margin: 0;
}
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

If utilizing a buffer geometry is your preference, then access the vertex coordinates through methods in THREE.BufferAttibute(), such as .setX, .setY, .setZ, and more.

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

Tips for interpreting JSONP objects

After setting up this HTML file to send a GET request to the random word API (wordnik) server, I received a response that looked like this: [{"id":2998982,"word":"failproof"}] My goal is to extract the "word" part from the response, but I'm struggli ...

React: Import default export as a string

Help needed with JSON data import import dataOption1 from './Option1.json' import dataOption2 from './Option2.json' async setParamsByDomain(optionUser) { await this.setState({ jsonName: "data"+ optionUser}); console.log(t ...

Is there a way for mocha to conduct a recursive search within my `src` directory in order to find a specific

In my npm project, I want to replicate the structure used by Meteor: there is a source file called client.js and its corresponding test file named client.tests.js residing in the src/ directory. The tests should be executed with the npm test command. I am ...

Highcharts facing issues with data rendering

This is the JSON data I have: [ { "project_title":"sdsdsd", "project_ref_id":"112", "amount":"232323.00", "months":"Mar-2015" },{ "project_title":"test project 44", "project_ref_id":"113", "a ...

I've been waiting forever for Product.find() to return some results, but it seems to

I have been encountering an issue where my code is supposed to return an empty object of a product but instead it just keeps loading forever. I have thoroughly checked through the code and explored every possible scenario where an error could be occurring, ...

Determine the height of an element within an ng-repeat directive once the data has been fetched from an

After sending an ajax request to fetch a list of products, I use angular's ng-repeat to render them. I am attempting to retrieve the height of a div element that contains one product in the list. However, the console always displays "0" as the result ...

The SimpleHTTPServer is causing Google Maps Places Autocomplete feature to malfunction

Currently, I am implementing a location search feature along with form auto-fill using the google.maps.places.Autocomplete functionality. While accessing the HTML file directly (file:///location.html), everything is functioning as expected. However, when ...

"Implementing a function triggered by a change event within a concealed input

I am working with two AJAX functions. The first function takes the input from the first field, concatenates a string to it, and then updates the value of the second hidden input field. However, the second function is supposed to detect any changes in thi ...

Oops! There seems to be an issue as the system cannot locate the declaration file for the module called 'react-search-input'

I'm attempting to set up react-input-search, but I keep encountering an error: The system is unable to find a declaration file for the module 'react-search-input'. The implied type in '.../app/node_modules/react-search-input/lib/inde ...

Unable to display modal pop-up in ASP.NET Core MVC web application

I have developed a web application using ASP.NET CORE MVC. I encountered an unusual issue while trying to display a modal popup using JQuery. The div structure I am working with is as follows: <div class="modal fade" tabindex="-1" r ...

Steps to insert an image object into a table

Note: The image in the database is named "profileImage." I want to create a dynamic image object similar to other objects when I insert this code. { label: "Image", name: "profileImage", } It will display the image endpoint as 3704545668418.PNG and ...

Creating a React component to format and display a JSON array using TypeScript

This information is currently stored in a database. [ { "id": "0", "item": { "title": "City1" } }, { "id": "1", "item": { "title": "City2" } } ] The data can now be found in the city property. The data is bein ...

Tips on validating if a form has already been submitted using JavaScript and AJAX to prevent duplicate submissions

Exploring the world of web development, I stumbled upon a fascinating component - forms in JavaScript or jQuery. However, here lies my dilemma: In JS: const themeFolder = object_name.templateUrl; const urlAjax = themeFolder + '/FormHandler.php&apos ...

setting a callback function as a variable

I have encountered an issue where I am passing a callback function but unable to call it when the onreadystatechange changes its value, specifically request.onreadystatechange = func. Even though I receive a response from the server when making the ajax ...

I want to learn how to iterate through an API response object in React and extract the 'urls' link for images

I'm currently facing an issue while attempting to iterate over an Object in React that is received from an API. My goal is to extract the 'regular' URL link from the object. I have a state variable called 'searchImages' which store ...

My content is being obstructed by a single-page navigation system

I attempted to create a simplified version of the issue I am facing. Basically, I am working on a header with navigation that stays at the top of the page while scrolling. The problem arises when clicking on a section in the navigation. The screen scrolls ...

Identifying strings from an array in the input using JavaScript and then displaying the identified string

Can you help me create a function that will detect if a user types one of the strings from a list and then output which string was typed in the console? HTML <input id="inputText"></input> JS window.onload = function(){ var inputText = do ...

What is the process of invoking a secondary "external" function with Nodejs, Expressjs, and bluebird?

Struggling with creating a nodejs application, a new area for me. I've managed to work with Promises and fetch data from a database. Take a look at the code below: myModel.js var express = require('express'); var app = express(); var Promi ...

Create a new visual masterpiece using Canvas by repurposing an

I am currently working on the following code snippet; export default async function draw(elRef : RefObject<HTMLCanvasElement>, tileData : TileProps) { const canvas = elRef.current!; const ctx = canvas.getContext('2d')!; ctx.clearRect( ...

Enhance the visual appeal of mandatory input fields in virtuemart by incorporating star symbols

Is there a way to incorporate red stars into the form for mandatory input fields within Virtuemart 1.x? ...