Syntax
c=rgb2char(RGB)
Input Parameter
Output Parameter
Examples
rgb2char([255 255 0])
rgb2char(char2rgb('krgbw'))
Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, rgb2char
, converts RGB color values into a single character representing a color. It is part of the SG-Library and was introduced in SolidGeometry 4.4.
Input Parameters
- RGBA: A matrix where each row represents an RGB color value in the format [R G B].
Output Results
- ci: A string of color characters corresponding to each RGB input.
Algorithm Steps
- Determine the number of colors,
nc
, by checking the number of rows in the RGBA
matrix.
- Define a string
colbar
containing the characters 'kbgcrmyw', which represent the colors black, blue, green, cyan, red, magenta, yellow, and white, respectively.
- Initialize the output string
ci
with spaces, having the same length as the number of colors, nc
.
- Iterate over each row in the
RGBA
matrix:
- Extract the RGB values for the current color.
- Calculate an index
c
based on the RGB values:
- Add 4 to the index if the red component is greater than 127.
- Add 2 to the index if the green component is greater than 127.
- Add 1 to the index if the blue component is greater than 127.
- Use the calculated index to select a character from
colbar
.
- Assign the selected character to the corresponding position in the output string
ci
.
The function does not produce any graphical output unless the commented-out section is activated, which would create a 3D plot with lighting effects.
Algorithm explaination created using ChatGPT on 2025-08-18 23:12. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21