question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating a plane in between 2 points.

See original GitHub issue

Hi Again Guys,

This is not an issue with Three.js but rather a general query. I wish to draw a simple model I have stored as a set of 2d points (x1,y1),(x2,y2). Each pair of points represents a wall which I was drawing.

I was originally doing this by loading in an xml file and filling up an array of vertices which I then drew using a bit of code similar to this -

    gl.bindBuffer(gl.ARRAY_BUFFER, walls3DVertexColorBuffer);
    gl.vertexAttribPointer(shaderProgram.vertexColorAttribute, walls3DVertexColorBuffer.itemSize, gl.FLOAT, false, 0, 0);
    setMatrixUniforms();
    gl.drawArrays(gl.TRIANGLES, 0, walls3DVertexPositionBuffer.numItems);

What would you guys recommend I do to draw the same scene in Three.js?

Is it advisable to create a large array of planes and assign each of these a position using my vertices? Or is there a faster way. I am also concerned about the normals and how the will appear with lighting etc…

All help is as always, much appreciated!

Kris.

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mrdoobcommented, Aug 22, 2011

I think this is the code you’re looking for:

var point1 = new THREE.Vector3( Math.random() * 200 - 100, 0, Math.random() * 200 - 100 );
var point2 = new THREE.Vector3( Math.random() * 200 - 100, 0, Math.random() * 200 - 100 );

var vector12 = new THREE.Vector3().copy( point2 ).subSelf( point1 );
var point3 = new THREE.Vector3().copy( vector12 ).multiplyScalar( 0.5 ).addSelf( point1 );

var sphere = new THREE.SphereGeometry( 2, 10, 10 );

var point1mesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xff0000 } ) );
point1mesh.position.copy( point1 );
scene.addObject( point1mesh );

var point2mesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x0000ff } ) );
point2mesh.position.copy( point2 );
scene.addObject( point2mesh );

var plane = new THREE.PlaneGeometry( 1, 1, 1 );

var wall = new THREE.Mesh( plane, new THREE.MeshBasicMaterial( { color: 0x00ff00 } ) );
wall.position.copy( point3 );
wall.position.y = 50;
wall.scale.x = vector12.length();
wall.scale.y = wall.position.y * 2;
wall.rotation.y = - Math.atan2( vector12.z, vector12.x );
wall.doubleSided = true;
scene.addObject( wall );
Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining a plane using only 2 points (and an axis)
Imagine you model this using table and a piece of paper. The axis along the table are X and Y and the axis...
Read more >
Distance in the Coordinate Plane | College Algebra
Derived from the Pythagorean Theorem, the distance formula is used to find the distance between two points in the plane. The Pythagorean Theorem,...
Read more >
plane equation from 2 points | Free Math Help Forum
Think of the paper as a plane. Now given two points in space place the pencil so that it passes through those two...
Read more >
Fusion 360 Help | Create a plane through two edges | Autodesk
Create a plane through two edges · On the toolbar, select Construct > Plane Through Two Edges plane through two edges icon ....
Read more >
How to Find the Distance Between 2 Points in the Plane
The values in the formula are found by the coordinates of the points given. Coordinate Pair: This is a method of denoting the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found