# Point-Triangle Collision

**URL:** <https://discourse.processing.org/t/point-triangle-collision/3187>\
**Category:** Coding Questions\
**Created:** [September 2, 2018, 4:18am UTC](https://discourse.processing.org/t/point-triangle-collision/3187 "2018-09-02T04:18:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Odermonicon](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Odermonicon](https://discourse.processing.org/u/Odermonicon)\
**Post date:** [September 2, 2018, 4:18am UTC](https://discourse.processing.org/t/point-triangle-collision/3187/1 "2018-09-02T04:18:59Z")

</div>

I am creating a 3D engine that does not use wireframe, but rendering the triangles Is the problem! I have seen other code but I don’t understand it. [https://www.openprocessing.org/sketch/6380#](https://www.openprocessing.org/sketch/6380#)

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [September 2, 2018, 4:37am UTC](https://discourse.processing.org/t/point-triangle-collision/3187/2 "2018-09-02T04:37:19Z")

</div>

What you don’t understand? Your question is really generic. It does not help anybody to ask this type of questions. Instead, try to provide a bit more context of what you want to do and what is your difficulty. Also, provide some code as it shows your current approach to your problem, and it shows your Processing code level. It really helps to provide more efficient feedback at the end.

Kf

---

<div class="post-metadata">

**Author:** ![Odermonicon](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Odermonicon](https://discourse.processing.org/u/Odermonicon)\
**Post date:** [September 2, 2018, 6:47am UTC](https://discourse.processing.org/t/point-triangle-collision/3187/3 "2018-09-02T06:47:02Z")

</div>

I have 0 lines of code… I was already lost before I even tried to write a single letter, although here is the rest of my code : [https://pastebin.com/m5B6fEZd](https://pastebin.com/m5B6fEZd)

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 2, 2018, 6:50am UTC](https://discourse.processing.org/t/point-triangle-collision/3187/4 "2018-09-02T06:50:58Z")

</div>

Hi Odermonicon,

The thing is that what you want to do is not clear enough.

> [@Odermonicon](#):
>
> I am creating a 3D engine that does not use wireframe, but rendering the triangles Is the problem!

I did not understand that sentence at all.

Please explain the context, then what you are trying to do and then what problem you are facing.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 3, 2018, 4:17pm UTC](https://discourse.processing.org/t/point-triangle-collision/3187/5 "2018-09-03T16:17:55Z")

</div>

@Odermonicon – thank you for sharing your code. People on the forum have a fair amount of experience with 3D rendering, and are interested in your problem and would like to help you. However, you need to provide many more details and be more concrete. Consider if you asked this question about some other topic:

> **Eggs-Flour combination**  
> I am creating a cake that does not use sugar, but beating the eggs is a problem. I have seen other recipes but I do not understand them.

or

> **Engine-Camshaft connection**  
> I am creating a car that does not use gas, but camshaft rotation is a problem. I have seen other motor designs but I do not understand them.

Some example questions:

- What is “a problem”, specifically? Which step doesn’t work, and how can you tell – what should happen, and what happens instead?
- If it doesn’t use something, what does it use instead – or is that not relevant?
- You have seen other examples – what are they? Can you link to them? Is one of them the inspiration for this project?

---

<div class="post-metadata">

**Author:** ![Odermonicon](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Odermonicon](https://discourse.processing.org/u/Odermonicon)\
**Post date:** [September 6, 2018, 5:51pm UTC](https://discourse.processing.org/t/point-triangle-collision/3187/6 "2018-09-06T17:51:51Z")

</div>

I would like a simple algorithm to draw a triangle pixel by pixel so I can draw triangles that are in front of each other. I honestly don’t know what else to say, I’m just lost.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 6, 2018, 11:56pm UTC](https://discourse.processing.org/t/point-triangle-collision/3187/7 "2018-09-06T23:56:12Z")

</div>

> [@Odermonicon](#):
>
> I would like a simple algorithm to draw a triangle pixel by pixel **so I can draw triangles that are in front of each other**. I honestly don’t know what else to say, I’m just lost.

I honestly still can’t tell if you are asking for a line drawing algorithm or if you don’t know how to draw a triangle in P3D.

- Can you use `PShape.vertex()`?
- Can you use `beginShape(TRIANGLE_STRIP)`?
- Can you use `beginShape(TRIANGLE_FAN)`?

If you cannot use any of these things, and you are not allowed to or do not wish to for some reason…

…do you already have the algorithm for drawing your “pixel by pixel” line? if so, share it – and we can use that line algorithm to build the triangle algorithm. If not, you need to learn how to draw a line. Can you use `PVector.lerp()`, or do you need to write line rendering from scratch?

Here is an example of a few of the many ways you can draw triangles in P3D. Hopefully one of them is helpful!

```auto
PShape s;
PShape strip;

void setup() {
  size(200, 200, P3D);

  // make a triangle with PShape
  s = createShape();
  s.beginShape();
  s.vertex( 0, 0, 0);
  s.vertex(25, 50, 0);
  s.vertex(50, 0, 0);
  s.endShape(CLOSE);

  // make multiple triangles
  // using TRIANGLE_STRIP
  strip = createShape();
  strip.beginShape(TRIANGLE_STRIP);
  strip.vertex( 0, 0, 0);
  strip.vertex( 25, 50, 0);
  strip.vertex( 50, 0, 0);
  strip.vertex( 75, 50, 0);
  strip.vertex(100, 0, 0);
  strip.vertex(125, 50, 0);
  strip.vertex(150, 0, 0);
  strip.vertex(175, 50, 0);
  strip.endShape();
}

void draw() {
  background(192);

  // draw the triangle shape
  shape(s, width/2 - 45, height/2 - 45);

  // draw a copy of the triangle shape
  // that moves in z-depth according to
  // the mouse position.
  pushMatrix();
  translate(0, 0, mouseX);
  shape(s, width/2 - 45, height/2 - 45);
  popMatrix();

  // draw the strip of triangles
  // multiple times
  // ... rotate them in space
  pushMatrix();
  translate(10, height/2 + 45);
  rotateX(-QUARTER_PI/2);
  for (int i=0; i<5; i++) {
    translate(0, 0, -25);
    shape(strip, 0, 0);
  }
  popMatrix();

  // draw a triangle using lines
  pushMatrix();
  translate(180, 10);
  rotateZ(HALF_PI);
  rotateY(QUARTER_PI);
  line( 0, 0, 25, 50);
  line(25, 50, 50, 0);
  line(50, 0, 0, 0);
  popMatrix();
}

```

 ![10%20PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e8a68eefeeb77f76d83bb4fcc482d022be6f10a3.jpeg)

You may also be interested in Processing examples and tutorials like:

- [https://processing.org/examples/texturetriangle.html](https://processing.org/examples/texturetriangle.html)
- [PShape / Processing.org](https://www.processing.org/tutorials/pshape/)
