3
$\begingroup$

Basically I want to create an object with specified coordinates and adjacency table, like in page two of this article.

I'm completely new to using Mathematica, any help would be great!

EDIT: So I want to plot an object like this,

and then I want to apply a perspective projection to it. (I will make the coordinates of the object I wish to plot, and will make an adjacency matrix which notes which points are connected and which are not). How could I do this in Mathematica?

Here are examples for the coordinate list and adjacency matrix (kindly supplied by kguler):

pnts = {{-6.5, -2, -2.5}, {-6.5, -2, 2.5}, {-6.5, .5, 2.5}, {-6.5, .5, -2.5}, 
        {-2.5, .5, -2.5}, {-2.5, .5, 2.5}, {-.75, 2, -2.5}, {-.75, 2, 2.5},
        {3.25, 2, -2.5}, {3.25, 2, 2.5}, {4.5, .5, -2.5}, {4.5, .5, 2.5}, 
        {6.5, .5, -2.5}, {6.5, .5, 2.5}, {6.5, -2, 2.5}, {6.5, -2, -2.5}};

adjmat = {{0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 
         {1, 0, 1,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
         {0, 1, 0, 1, 0, 1, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0}, 
         {1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0}, 
         {0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
         {0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, 
         {0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0}, 
         {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, 
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0}, 
         {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0}, 
         {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0}, 
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0}, 
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0}, 
         {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, 
         {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0}};
$\endgroup$
7
  • 2
    $\begingroup$ You should look through the docs and learn the basics. Then try to implement what you want and come back with a specific question when you get stuck. In particular, you need to post an example. $\endgroup$
    – Jens
    Mar 21, 2015 at 3:37
  • 1
    $\begingroup$ So we can get a better idea of what you are looking for, can you give us an example of such an object? Edit your quest to add the description; do not put it into a comment. $\endgroup$
    – m_goldberg
    Mar 21, 2015 at 3:40
  • 1
    $\begingroup$ I thinks it's clear enough what OP wants. He has a list of coordinates of vertices of a polyhedron and he has an adjacency matrix, which describes where edges of said polyhedron exist (between which pairs of vertices exists an edge). Studying documentation of GraphicsComplex will surely help. $\endgroup$
    – LLlAMnYP
    Mar 21, 2015 at 8:58
  • $\begingroup$ I concur with @LLlAMnYP that the question is clear enough. It's only lacking some example data to work with. As he shows making some yourself is not that difficult either. I wouldn't cllose it for this reason. $\endgroup$ Mar 21, 2015 at 10:38
  • 1
    $\begingroup$ At the time of the mods' comments OP had not yet been edited. $\endgroup$
    – LLlAMnYP
    Mar 21, 2015 at 11:42

2 Answers 2

8
$\begingroup$
adjmat = {{0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, 
          {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
          {0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
          {1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
          {0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
          {0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, 
          {0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0}, 
          {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, 
          {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0}, 
          {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0}, 
          {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0}, 
          {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0}, 
          {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1},
          {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0}, 
          {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, 
          {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0}};

pnts = {{-6.5, -2, -2.5}, {-6.5, -2, 2.5}, {-6.5, .5, 2.5}, {-6.5, .5, -2.5}, 
        {-2.5, .5, -2.5}, {-2.5, .5, 2.5}, {-.75, 2, -2.5}, {-.75, 2, 2.5},
        {3.25, 2, -2.5}, {3.25, 2, 2.5}, {4.5, .5, -2.5}, {4.5, .5, 2.5}, 
        {6.5, .5, -2.5}, {6.5, .5, 2.5}, {6.5, -2, 2.5}, {6.5, -2, -2.5}};

Using AdjacencyGraph:

grph = AdjacencyGraph[adjmat, VertexCoordinates -> pnts, 
  VertexSize -> .01, Axes -> True, ImageSize -> 500]

enter image description here

grph2 = AdjacencyGraph[adjmat, VertexCoordinates -> pnts, 
  EdgeShapeFunction -> "Line", EdgeStyle -> Thick, VertexSize -> 0, 
  Axes -> True, ImageSize -> 500]

enter image description here

Use Show@grph2 to get a Graphics3D object:

Show[grph2, ViewPoint -> {0, 1, -3}] 

enter image description here

Using Graphics3D and GraphicsComplex:

To get the line indices you can use MapIndexed as in @LLlAMnYP's answer. An alternative way is to use SparseArray[adjmat]["NonzeroPositions"]:

Graphics3D[GraphicsComplex[pnts, Line@SparseArray[adjmat]["NonzeroPositions"]], 
 ViewPoint -> {0, 1, -3}, ImageSize -> 500, Axes -> True, Boxed->False]

enter image description here

$\endgroup$
1
  • $\begingroup$ I copied your example data into the question, hope you don't mind. I think it's worth keeping open. +1 of course. $\endgroup$ Mar 21, 2015 at 14:16
4
$\begingroup$

Here is a very simple version of what you seem to be looking for. First I enter some fake data:

points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 1}, {0, 0, 1}, {0, 1, 0}};

am = {{0, 1, 0, 0, 1, 0}, {1, 0, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 1},
        {0, 0, 1, 0, 0, 1}, {1, 1, 0, 0, 0, 0}, {0, 0, 1, 1, 0, 0}};

i.e. points (their coordinates) and adjacency matrix, respectively.

Then I want to get from the adjacency matrix to a list like {{5,6},{3,4},{1,4}...} which means "there is an edge between the 5th and 6th point, an edge between 3rd and 4th, 1st and 4th and so on". This could be done (and probably better done) with MMA's capabilities of working with graphs, but I'm not too fluent with those, so I just used this line of code:

lines = Cases[Flatten[MapIndexed[(If[# == 1, #2] &), am, {2}], 1], _List]

Which returns

{{1, 2}, {1, 5}, {2, 1}, {2, 5}, {3, 4}, {3, 6}, {4, 3}, {4, 6}, {5, 1}, {5, 2}, {6, 3}, {6, 4}}

Finally I use GraphicsComplex to plot this.

Graphics3D[GraphicsComplex[points, {Line[lines]}], Axes -> False, Boxed -> False]

This is easily extendable to your Toyota polyhedron if you go to all the trouble of inputting the points and that 16x16 matrix.

$\endgroup$
3
  • $\begingroup$ Why didn't you use lines = Cases[ Flatten[MapIndexed[(If[# == 1, #2] &), adjmat, {2}], 1], _List] and Graphics3D[GraphicsComplex[pnts, {Line[lines]}], Axes -> False, Boxed -> False], which had matched the OP's actual data? $\endgroup$
    – Jinxed
    Mar 21, 2015 at 14:32
  • $\begingroup$ @Jinxed, the OP didn't include data - I copied it in from kguler's answer because I though it was worth keeping the question open and all it really lacked was example data. $\endgroup$ Mar 21, 2015 at 14:37
  • $\begingroup$ Ah, I see now. It was the edit. Missed that. $\endgroup$
    – Jinxed
    Mar 21, 2015 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.