Home > Backend Development > C++ > Explaining donut like ears old Part-2

Explaining donut like ears old Part-2

Barbara Streisand
Release: 2024-12-13 02:07:14
Original
552 people have browsed it

Explaining donut like ears old Part-2

Matrix Multiply

To multiply singleRow and a matrix, in C we will create a function and in Java, we will create a public static function in Matrix

In C

singleRow multiply(singleRow m1, Matrix m2) {
    singleRow res;
    res.a1 = (m1.a1 * m2.a1.a1) + (m1.a2 * m2.a2.a1) + (m1.a3 * m2.a3.a1);
    res.a2 = (m1.a1 * m2.a1.a2) + (m1.a2 * m2.a2.a2) + (m1.a3 * m2.a3.a2);
    res.a3 = (m1.a1 * m2.a1.a3) + (m1.a2 * m2.a2.a3) + (m1.a3 * m2.a3.a3);
    return res;
}
Copy after login

In Java

class Matrix {
  public static singleRow multiply(singleRow m1, Matrix m2) {
    singleRow res = new singleRow(0, 0, 0);
    res.a1 = (m1.a1 * m2.a1.a1) + (m1.a2 * m2.a2.a1) + (m1.a3 * m2.a3.a1);
    res.a2 = (m1.a1 * m2.a1.a2) + (m1.a2 * m2.a2.a2) + (m1.a3 * m2.a3.a2);
    res.a3 = (m1.a1 * m2.a1.a3) + (m1.a2 * m2.a2.a3) + (m1.a3 * m2.a3.a3);
    return res;
  }
}
Copy after login

Main func. body

Let screen height = 22 and width = 80

total area = 1760

A = 0, B = 0
A is angle for rotation on X-axis, B is angle for rotation on Z-axis, when we rotate circle on Y-axis, it becomes donut
ϕ for Y-axis, θ for creating circle

create 2 arrays of 1760, 1 that stores donuts characters to print, other that stores z index maybe in double type

double zBuffer[1760];
char buffer[1760];
Copy after login

create a new screen with printf("x1b[2J");
and add infinite loop

while (1) {
}
Copy after login

The above is the detailed content of Explaining donut like ears old Part-2. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template